class ThreadSystem_exit implements Runnable
{
public static void test()
{
try{
for(int i=0;i<10;i++)
{
System.out.println(i);
Thread.sleep(1000);// 睡眠时间为1秒
//System.exit(0);
}
}catch(Exception e)
{
e.printStackTrace();
}
}
@Override
public void run()
{
try{
for(int i=0;i<10;i++)
{
System.out.println("RUN:"+i);
Thread.sleep(1000);// 睡眠时间为1秒
System.exit(0);
}
}catch(Exception e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
new Thread(new ThreadSleep()).start();
test();
System.out.println("Hello World!");
}
}
/*
0
RUN:0
1
RUN:1
2
RUN:2
3
RUN:3
4
RUN:4
5
RUN:5
6
RUN:6
7
RUN:7
8
RUN:8
9
RUN:9
Hello World!
请按任意键继续. . .
*/