您的位置:首页 > 编程语言 > Java开发

Java线程学习03/【线程创建的俩种方法】/byme

2018-02-09 18:30 260 查看

Code:


package lp_2018_02_09_01;

public class thread03 extends Thread {
private String threadName;

public thread03(String name) {
this.threadName = name;
}

public void run() {
while(true) {
System.out.println("This is " + this.threadName + " thread.");
}
}

}
package lp_2018_02_09_01;

public class thread04 implements Runnable {
private String threadName;

public thread04(String name) {
this.threadName = name;
}

public void paly() {
while(true) {
System.out.println(this.threadName);
}
}

@Override
public void run() {
this.paly();
}
}
package lp_2018_02_09_01;

public class test {
public static void main(String [] args) {

thread03 lp_1 = new thread03("lp_1");
thread03 lp_2 = new thread03("lp_2");
lp_1.start();
lp_2.start();

thread04 lp_a = new thread04("lp_a");
thread04 lp_b = new thread04("lp_b");
lp_a.run();
lp_b.run();

}
}


Effect:

太长,没有截图。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Java 多线程