Welcome To The World Of Hacking


Learn Hacking|Teach Hacking|Learn To Secure|Learn To Code

Wednesday

JAVA PROGRAMMING TUTORIAL 22: THREADS

import java.util.Random;

public class HackDefence implements Runnable{

String name;

int time;

Random r = new Random();

public HackDefence(String s){

name = s;

time = r.nextInt(999);

}

        public void run(){

     try{

           System.out.printf("%s is down for %d\n",name,time);

           Thread.sleep(time);

            System.out.printf("%s is going \n", name);

         }catch(Exception e){};

       }

        public static void main(String[]args){

      Thread t1 = new Thread(new HackDefence("site"));

      Thread t2 = new Thread(new HackDefence("network"));

              t1.start();

      t2.start();

       }

}

OUTPUT:


No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...