Created
April 3, 2012 13:55
-
-
Save raheelahmad/2292210 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Random; | |
public class ThreadingThings implements Runnable{ | |
int myID; | |
Random gen; | |
public ThreadingThings(int anID) { | |
myID = anID; | |
gen = new Random(); | |
} | |
public void run() { | |
System.out.println("Running thread " + myID); | |
int count = 0; | |
while(true) { | |
System.out.println(myID +": At " + count++); | |
try { | |
Thread.sleep(Math.abs(gen.nextInt())%3 * 1000); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
public static void main(String[] args) { | |
Thread t1 = new Thread(new ThreadingThings(1)); | |
Thread t2 = new Thread(new ThreadingThings(2)); | |
t1.start(); | |
t2.start(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment