SCJP6 96% | SCWCD5 81% | SCDJWS5 79%
Minhaj kaimkhani wrote:yes true, they said its unsafe take a look on >> http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Thread.html#stop%28%29
SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Minhaj kaimkhani wrote:moreover take a look on following example public class TestClass extends Thread{ private boolean flag = true; public void shutdown(){ System.out.println("ah!! someone killed me :("); flag = false; } public void run(){ while(flag){ System.out.println("uhu!! am still alive.."); } } public static void main(String[] args) throws Exception { TestClass clazz = new TestClass(); clazz.start(); clazz.shutdown(); } }
In a multithreaded environment the shared variable should declared as volatile because of visibility issues when sharing a variable between threads.