forum

Home / DeveloperSection / Forums / How to interrupt a Thread in Java

How to interrupt a Thread in Java

Samuel Fernandes 2676 30-Apr-2015
Hello, i know how to interrupt a thread in java but somehow it is not working. 
My Application looks like this 
public class MyThread {
 
    public static void main(String[] args) {
        Thread testThread = new Thread(new GreatThread());
        testThread.start();
    }
     
}
public class GreatThread implements Runnable {
 
    @Override
    public void run() {
        System.out.println("I am there!");
         
        Thread.currentThread().interrupt();
         
        System.out.println("Still not interrupted!");
 
    }
 
}

Why is this not working? 
I always read that interrupting a Thread is so much better than the .stop method but somehow the interrupt method don't work? 


Updated on 30-Apr-2015

Can you answer this question?


Answer

1 Answers

Liked By