public class test
{
public static void main(String[] args)
{
ThreadTest t=new ThreadTest();
Thread pp=new Thread(t);
pp.start();
int i=0;
while(true)
{
if(i==100)
{
try
{
pp.join();
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
System.out.println("main Thread "+i++);
}
}
}
class ThreadTest implements Runnable
{
public void run()
{
String str=new String();
int i=0;
while(true)
{
System.out.println(Thread.currentThread().getName()+" "+i++);
}
}
}这段代码是什么意思,join有什么作用,感谢。为什么没有打印System.out.println("main Thread "+i++);。。感谢。。请教了
{
public static void main(String[] args)
{
ThreadTest t=new ThreadTest();
Thread pp=new Thread(t);
pp.start();
int i=0;
while(true)
{
if(i==100)
{
try
{
pp.join();
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
System.out.println("main Thread "+i++);
}
}
}
class ThreadTest implements Runnable
{
public void run()
{
String str=new String();
int i=0;
while(true)
{
System.out.println(Thread.currentThread().getName()+" "+i++);
}
}
}这段代码是什么意思,join有什么作用,感谢。为什么没有打印System.out.println("main Thread "+i++);。。感谢。。请教了
System.out.println("main Thread "+i++);
改成
i++;
System.out.println("main Thread "+i);
ThreadTest t=new ThreadTest();
Thread pp=new Thread(t);
pp.start();
这句话就是声明了一格线程实例 ,pp.start()这句调用了threattest的run() 方法!好了 给分吧!!!
点"管理",给分
{
public static void main(String[] args)
{
ThreadTest t=new ThreadTest();
Thread pp=new Thread(t);
pp.start();
int i=0;
while(true)
{
if(i==100)
{
try
{
pp.join();
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
System.out.println("main Thread "+i++);
try
{
Thread.currentThread().sleep(500);
}
catch(Exception e){}
}
}
}
class ThreadTest implements Runnable
{
public void run()
{
String str=new String();
int i=0;
while(i<200)
{
try
{
Thread.currentThread().sleep(500);
}
catch(Exception e){}
System.out.println(Thread.currentThread().getName()+" "+i++);
}
}
}
public class TestThread { public static void main(String[] args)
{
ThreadTest t=new ThreadTest();
Thread pp=new Thread(t);
pp.start();
int i=0;
while(true)
{
if(i==100)
{
try
{
pp.sleep(1000);
//pp.join();用这个达不到你说的那种效果 。
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
} System.out.println("main Thread "+i++);
}
}
}
class ThreadTest implements Runnable
{
public void run()
{
String str=new String();
int i=0;
while(true)
{
System.out.println(Thread.currentThread().getName()+" "+i++);
}
}
}
永远不会结束故
System.out.println("main Thread "+i++);
永远不会被执行到!
就会有下面的打印了
等待该线程终止的时间最长为 millis 毫秒。超时为 0 意味着要一直等下去。