Skip to content

Instantly share code, notes, and snippets.

@raheelahmad
Created April 3, 2012 13:55
Show Gist options
  • Save raheelahmad/2292210 to your computer and use it in GitHub Desktop.
Save raheelahmad/2292210 to your computer and use it in GitHub Desktop.
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