×

Loading...

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 -04:00
This post has been archived. It cannot be replied.
Page address has been copied. To share, click to copy page address.
Share Online by QR Code

Back To Topic: Toy code for Java Thread

Back To Forum: HOME枫下论坛枫下论坛主坛工作学习IT杂谈