package thread;
public class PrintText {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("print text");
PrintThread t = new PrintThread();
t.start();
for(int i=0; i<10000; i++) {
System.out.println(" good");
}
}
}
class PrintThread extends Thread {
public void run() {
for(int i=0; i<5; i++) {
System.out.println("Nice ");
}
}
public class PrintText {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("print text");
PrintThread t = new PrintThread();
t.start();
for(int i=0; i<10000; i++) {
System.out.println(" good");
}
}
}
class PrintThread extends Thread {
public void run() {
for(int i=0; i<5; i++) {
System.out.println("Nice ");
}
}
}
主线程和打印线程并发运行,调用start时,会有两个操作,启动新的线程;调用run方法.run 方法介绍启动的新线程结束