sraveend
asked on
java programming in Thread
public class mythread extends Thread
{
private boolean continuerun;
public void setcontinuerun(boolean setc)
{
continuerun=setc;
}
public void run()
{
continuerun=true;
while(continuerun)
{
System.out.println("Iam running");
}
System.out.println("Iam tired of running");
}
public static void main(String args[])
{
mythread mm=new mythread();
mm.start();
//try
//{
// Thread.currentThread().sle ep(1000);
//}
//catch(InterruptedExcepti on ie)
//{
//}
mm.setcontinuerun(false);
}
}
My question is when is only when i add the sleep() method i could see the statement "Iam tired of running" ,why?
{
private boolean continuerun;
public void setcontinuerun(boolean setc)
{
continuerun=setc;
}
public void run()
{
continuerun=true;
while(continuerun)
{
System.out.println("Iam running");
}
System.out.println("Iam tired of running");
}
public static void main(String args[])
{
mythread mm=new mythread();
mm.start();
//try
//{
// Thread.currentThread().sle
//}
//catch(InterruptedExcepti
//{
//}
mm.setcontinuerun(false);
}
}
My question is when is only when i add the sleep() method i could see the statement "Iam tired of running" ,why?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Could u suggest me any usefull link related to thread and synchronization
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
mm.setPriority(10);