一个很简单的小java线程程序,一个main线程,一个t线程,t先打印1~100,main再打印101,我想要 t打印一个数sleep 1秒,那么这个Thread.sleep();加在哪里好呢?
try{
Thread.sleep(1000);
}catch(InterruptedException ex){
ex.printStackTrace();
}import java.lang.InterruptedException;
class ThreadTest1 extends Thread
{
public void run(){
for(int i = 0 ; i < 100 ; i++){
System.out.print(i + "*");
}
}
public static void main(String[] args)
{
ThreadTest1 t = new ThreadTest1();
t.start();
try{
t.join();
}catch(java.lang.InterruptedException e){
e.printStackTrace();
}
System.out.println(101);
}
}
try{
Thread.sleep(1000);
}catch(InterruptedException ex){
ex.printStackTrace();
}import java.lang.InterruptedException;
class ThreadTest1 extends Thread
{
public void run(){
for(int i = 0 ; i < 100 ; i++){
System.out.print(i + "*");
}
}
public static void main(String[] args)
{
ThreadTest1 t = new ThreadTest1();
t.start();
try{
t.join();
}catch(java.lang.InterruptedException e){
e.printStackTrace();
}
System.out.println(101);
}
}
楼主【fuqiang229】截止到2008-07-13 09:39:27的历史汇总数据(不包括此帖):
发帖的总数量:10 发帖的总分数:170 每贴平均分数:17
回帖的总数量:15 得分贴总数量:2 回帖的得分率:13%
结贴的总数量:8 结贴的总分数:150
无满意结贴数:0 无满意结贴分:0
未结的帖子数:2 未结的总分数:20
结贴的百分比:80.00 % 结分的百分比:88.24 %
无满意结贴率:0.00 % 无满意结分率:0.00 %
楼主加油
{
public void run()
{
for (int i = 0; i < 100; i++)
{
System.out.print(i + "*");
try
{
Thread.sleep(1000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
} public static void main(String[] args)
{
ThreadTest1 t = new ThreadTest1();
t.start();
try
{
t.join(); }
catch (java.lang.InterruptedException e)
{
e.printStackTrace();
}
System.out.println(101);
}
}
{
System.out.print(i + "*");
try
{
Thread.sleep(1000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}