Last active
October 8, 2016 17:29
-
-
Save Ansh1234/53d79a82bbbbd1871c6170920f45b915 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
public class StringPrinter { | |
private final ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(2, 2, 0, | |
TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>()); | |
public static void main(String[] args) { | |
new StringPrinter().printString(); | |
} | |
public void printString() { | |
for (int i = 1; i <= 6; i++) { | |
threadPoolExecutor.execute(getRunnable(i)); | |
} | |
} | |
private Runnable getRunnable(final int i) { | |
Runnable runnable = new Runnable() { | |
@Override | |
public void run() { | |
String randomString = RandomClass.getRandomString(i); | |
System.out.println("String returned is : + randomString); | |
} | |
}; | |
return runnable; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment