下面是创建一个新线程的例子:
Filename:twothread。java
classtwothreadimplementsRunnable{twothread(){Threadt1
=Thread。currentThread();t1。setName(”Thefirstmainthread”);
System。out。println(”Therunningthread:”+t1);Threadt2=new
Thread(this;”thesecondthread”);System。out。println(”creatanother
thread”);t2。start();try{System。out。println(”firstthreadwill
sleep”);Thread。sleep(3000);}catch(InterruptedExceptione)
{System。out。println(”firstthreadhaswrong”);}
System。out。println(”firstthreadexit”);}publicvoidrun(){try{for
(inti=0;i