Created
December 8, 2016 16:24
-
-
Save MridulS/7486898b6bb46e7ff99338a7c690f5c2 to your computer and use it in GitHub Desktop.
This file contains 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.concurrent.*; | |
import java.io.IOException; | |
class JumbleNames implements Runnable | |
{ | |
private String firstName, secondName; | |
private long delay; | |
public JumbleNames(String firstName, String secondName, long delay) | |
{ | |
this.firstName = firstName; | |
this.secondName = secondName; | |
this.delay = delay; | |
} | |
public void run(){ | |
try{ | |
System.out.println(firstName); | |
TimeUnit.MILLISECONDS.sleep(delay); | |
while(true){ | |
System.out.println(secondName); | |
} | |
} | |
catch(InterruptedException e) { | |
System.err.println("Interrupted"); | |
} | |
} | |
public static void main(String[] args){ | |
Thread t1 = new Thread(new JumbleNames("A", "B", 100)); | |
Thread t2 = new Thread(new JumbleNames("D", "E", 100)); | |
Thread t3 = new Thread(new JumbleNames("F", "G", 100)); | |
t1.setDaemon(true); | |
t2.setDaemon(true); | |
t3.setDaemon(true); | |
t1.start(); | |
t2.start(); | |
t3.start(); | |
System.out.println("Press Enter when you had enough"); | |
try{ | |
System.in.read(); | |
System.out.println("Enter pressed \n"); | |
} | |
catch(IOException e){ | |
System.err.println(e); | |
} | |
System.out.println("Ending main()"); | |
return; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment