­

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magnaaliqua. Ut enim ad minim veniam, quis nostrud exer ull labo nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor aliquip.

CONTOH PROGRAM YANG MENGGUNAKAN THREAD



CONTOH LAIN PROGRAM JAVA THREAD
Program Countdown Menggunakan Thread Pada Java

 public class CountDown implements Runnable{
 private static int startCount = 11;
 private int countDown = --startCount;
 private static int threadCount = 0;
 private int threadNumber = ++threadCount;
 public void run() {
System.out.println("Waktu tinggal "+countDown+" detik ( Thread nomer : "+threadNumber+" )");
if (countDown == 1) {
System.out.println("\nWaktu Habis ~ !!");
}
}
private static void doThreadCountdown() throws java.lang.InterruptedException{
for (int i = 0; i < 10; i++){
Thread.sleep(1000);
Runnable ot = new CountDown();
Thread th = new Thread(ot);
th.start();
}
}
 public static void main(String[] args) throwjava.lang.InterruptedException{
System.out.println("\nMenghitung mundur dalam 10 detik ...\n");
doThreadCountdown();}
}


Penjelasan :
Pada program ini menghasilkan 10 buah thread dengan menggunakan looping sebanyak 10 kali dan setiap thread yang tercipta dimanfaatkan untuk melakukan hitung mundur/countdown.

0 komentar:

Posting Komentar