Have a look at this code below..
public class TestThread extends Thread{
private
String mesg="";
public void run(){
while(!isInterrupted()) {
try {
sleep(1000);
}
catch(InterruptedException e){
}
System.out.println(mesg);
}
}
public TestThread(String m) {
mesg = m;
setName(m);
}
public static void main(String[] args){
TestThread t1=new TestThread("good");
TestThread t2=new TestThread("goodhey");
TestThread t3=new TestThread("goodheyhey");
t1.start(); t1.interrupt();
t2.start(); t2.interrupt();
t3.start(); t3.interrupt();
System.out.println("Hey");
}
Which is better for a check in "while"
isInterrupted or interrupted()