//第一种方法
import java.lang.Thread;
public class ThreadBaseMethod1
{
public static void main(String args[])
{
MyThread mt = new MyThread();
mt.start();
while(true)
{System.out.println("main Thread is running !");}
}
}
class MyThread extends Thread
{
public void run()
{
while(true)
{System.out.println(Thread.currentThread().getName()+"is running!");}
}
}
//第二种方法
import java.lang.Thread;public class ThreadBaseMethod2{ public static void main(String args[]) { new Thread(new MyThread()).start();
while(true) {System.out.println("main Thread is running !");} }
}
class MyThread implements Runnable{ public void run() { while(true) {System.out.println(Thread.currentThread().getName()+"is running!");}
}}
|