Thread t1 = new StopBoolean(); Thread t2 = new StopClose(); t1.start(); t2.start(); Thread.sleep(1000*5); ((StopBoolean)t1).shutDown(); ((StopClose )t2).shutDown();