几乎一年没看java,问下下面代码中的“以Runnable实现类的对象 作为Thread的target来创建Thread对象”
什么叫做Thread的target
public class SecondCreateThread implements Runnable {
public void run() {//线程执行体
for( int i=0; i<20; ++i ){
System.out.println( Thread.currentThread().getName()+" "+i );
}
}
public static void main(String[] args) {
for( int i=0; i<30; ++i ){
System.out.println( Thread.currentThread().getName()+" "+i );
if( i==20 ){
SecondCreateThread target = new SecondCreateThread( );
//以Runnable实现类的对象 作为Thread的target来创建Thread对象
new Thread( target, "线程1" ).start();
new Thread( target, "线程2" ).start();
}
}
}
}
潇湘沐
相关分类