//PROGRAM 12-8 class MyThread implements Runnable { private Thread t; private long n; // jumlah pengulangan yang dihasilkan private boolean selesai = false; MyThread(String nama, int prioritas) { t = new Thread(this, nama); t.setPriority(prioritas); n = 0; } public void run() { while (!selesai) { n++; } } public void start() { t.start(); } public void stop() { selesai = true; } public long getN() { return n; } public Thread getThread() { return t; } } class DemoPrioritasThread { public static void main(String[] args) throws InterruptedException { MyThread t1 = new MyThread("prioritas-tinggi", Thread.NORM_PRIORITY + 2); MyThread t2 = new MyThread("prioritas-rendah", Thread.NORM_PRIORITY - 2); t1.start(); t2.start(); // mengistirahatkan thread utama selama 5 detik Thread.sleep(5000); t1.stop(); t2.stop(); t1.getThread().join(); t2.getThread().join(); System.out.println("Jumlah pengulangan pada " + t1.getThread().getName() + ": " + t1.getN()); System.out.println("Jumlah pengulangan pada " + t2.getThread().getName() + ": " + t2.getN()); } }