OKIEWARDOYO

Java No.16

Aug 9th, 2012
6,226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.62 KB | None | 0 0
  1. class Tampilkan implements Runnable{
  2.  
  3.     @Override
  4.     public void run() {
  5.         for(int i = 0; i<5; i++){
  6.             System.out.println("Ini angka "+i);
  7.             try{
  8.                 Thread.sleep(100);//digunakan supaya cpu tidak terbebani
  9.             }catch(InterruptedException e){
  10.                 e.printStackTrace();
  11.             }
  12.         }
  13.     }
  14.    
  15. }
  16.  
  17. public class ContohThread {
  18.     public static void main(String[] args){
  19.         Thread tampil1 = new Thread(new Tampilkan());
  20.         tampil1.start();
  21.        
  22.         Thread tampil2 = new Thread(new Tampilkan());
  23.         tampil2.start();
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment