You need to wait for Thread complete. I added you a join call that blocks and wait for Thread complete before looking at the j value:
class s extends Thread{ int j=0; public void run() { try{ Thread.sleep(5000); } catch( Exception e ){} j = 100; } public static void main(String args[]) throws InterruptedException { s t1=new s(); t1.start(); t1.join() ;
tim_yates
source share