close
public class ThreadTest {
public static void main(String args[])
{
Thread thread1 = new Thread(new Runnable()
{
public void run()
{
for(int i = 0;i<10;i++)
System.out.println("Threa1: "+i);
}
}
);
thread1.setDaemon(true); //if thread1 is finish, thread2 is not yet,then stop thread1
thread1.start();
Thread thread2 = new Thread(new Runnable()
{
public void run()
{
Thread.yield();
for(int i=0;i<10;i++)
System.out.println("Thread2: "+i);
}
}
);
thread2.start();
}
}
全站熱搜