Skip to content

Instantly share code, notes, and snippets.

@orenmizr
Created August 8, 2013 14:23
Show Gist options
  • Save orenmizr/6185030 to your computer and use it in GitHub Desktop.
Save orenmizr/6185030 to your computer and use it in GitHub Desktop.
Java: Simple Thread Example
package com.crunchify;
public class CrunchifyThread {
/**
* @author Crunchify.com
*/
public static void main(String args[]) {
new ThreadTest("eBay").start();
new ThreadTest("Paypal").start();
new ThreadTest("Google").start();
}
}
class ThreadTest extends Thread {
public ThreadTest(String str) {
super(str);
}
public void run() {
for (int i = 0; i < 5; i++) {
System.out.println("Loop " + i + ": " + getName());
try {
sleep((int) (Math.random() * 2000));
} catch (InterruptedException e) {
}
}
System.out.println("Test Finished for: " + getName());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment