//PROGRAM 12-5 class MyThread extends Thread { // mendeklarasikan variabel boolean // untuk mengontrol pengulangan private boolean selesai = false; public void run() { int counter = 0; System.out.println("Thread anak dijalankan"); while (!selesai) { System.out.print((++counter) + " "); } System.out.println("Thread anak selesai"); } public void stopThread() { selesai = true; } } class DemoStopThread { public static void main(String[] args) throws InterruptedException { System.out.println("Thread utama dijalankan"); MyThread t = new MyThread(); // menjalankan thread anak t.start(); // mengistirahatkan thread utama selama 1/40 detik Thread.sleep(25); // menghentikan thread anak t.stopThread(); // JANGAN GUNAKAN: t.stop(); System.out.println("\nThread utama selesai"); } }