Have created the below class with global variable. But why my thread is not ending or become dead.
public class MTTest {
private static boolean isRequestToStop = false;
public static void main(String [] args) throws Exception{
Thread T = new Thread (new Runnable(){
public void run(){
while(!getRequestToStop()) {
//System.out.println(" Value is " +getRequestToStop() );
//System.out.println("Thread");
}
}
});
T.start();
Thread.sleep(1000);
setRequestToStop();
//isRequestToStop = true;
}
public static void setRequestToStop(){
System.out.println("--- setRequestToStop()--- Called");
isRequestToStop = true;
}
public static boolean getRequestToStop(){
return isRequestToStop;
}
}