Created
August 8, 2013 14:23
-
-
Save orenmizr/6185030 to your computer and use it in GitHub Desktop.
Java: Simple Thread Example
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
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