* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javathread;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author USer
*/
public class Javathread {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Thread t=new Thread();
final int warga=40;
final int teroris=60;
//kopasus
final Thread kopasus=new Thread(){
public void run(){
for (int i=0;i<=warga;i++)
{
System.out.println(i+" Warga yang terselamatkan");
if (i==20){
setName ("Warga sudah 20");
}
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
Logger.getLogger(Javathread.class.getName()).log(Level.SEVERE, null, ex);
}
}};
};
//marinir
final Thread marinir=new Thread(){
public void run(){
boolean status=true;
while (status){
if (kopasus.getName().equals("Warga sudah 20")){
for (int i=0;i<=teroris;i++){
System.out.println(i+" Membunuh Teroris");
if (i==60){
System.out.println("Masuklah Infantri");
}
try{
Thread.sleep(500);
} catch (InterruptedException ex)
{
Logger.getLogger(Javathread.class.getName()).log(Level.SEVERE, null, ex);
}
status=false;
}
}
}
};
};
kopasus.start();
marinir.start();
try {
kopasus.join();
} catch (InterruptedException ex) {
Logger.getLogger(Javathread.class.getName()).log(Level.SEVERE, null, ex);
}
try {
marinir.join();
} catch (InterruptedException ex) {
Logger.getLogger(Javathread.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
Tidak ada komentar:
Posting Komentar