Toy code for Java Thread

jabber (jabber)
This morning, I discussed Thread with a friend. We cooked up some toy code. I postit here for reference in the future discussion




class MyThread extends Thread
{

public void run()
{
int x=0;
while(x<10)
{
System.out.println("x=" +x);
try{
Thread.sleep(1000);
} catch (Exception e) {}
x++;
}


}
} //end of MyThread


public class Test
{
public static void main(String[] args)
{
try
{
MyThread mt = new MyThread();
mt.start();
Thread.sleep(15000);
System.out.println("I came here");
if(mt!=null)
{
System.out.println("I 'am not null");
if(!mt.isAlive())
{
System.out.println("I am dead!");

}

mt.start();
}
else
{
System.out.println("I 'am null");
}
}
catch (Exception e)
{
e.printStackTrace();

}


}
}//end of Test
(#13059@0)
2000-11-3 -05:00

回到话题: Toy code for Java Thread

回到论坛: HOME枫下论坛枫下论坛主坛工作学习IT杂谈

URL:   
http://www.rolia.net/zh/post.php?f=0&p=13059