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:
太长,没有截图。