I have a main () method that calls the Thread class and starts the thread. This thread has a while (threadBool) loop, so I need to stop it when I exit the program (by setting threadBool to false). Where is the best place to add addShutdownHook ()? In the main () method
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { public void run() { class.threadBool=false; } }));
or in the same class that started this thread
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { public void run() { threadBool=false; } }));
source share