Please see below code and find error or bugs :
public class Thread1 {
private static boolean interruptedTask=false;
private static class MyClass extends Thread{
public void run(){
while(!interruptedTask){
//Do some time consuming task for more than 5 secs
}
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Thread task=new MyClass();
task.start();
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
interruptedTask=true;
try {
task.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}