Created
August 10, 2014 17:41
-
-
Save AndrienkoAleksandr/b78b0e4e17b9c4facf90 to your computer and use it in GitHub Desktop.
callable without ExecutorService
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 Application2 { | |
public static class WordLengthCallable implements Callable { | |
public static int count = 0; | |
private final int numberOfThread = count++; | |
public Integer call() throws InterruptedException { | |
int sum = 0; | |
for (int i = 0; i < 100000; i++) { | |
sum += i; | |
} | |
System.out.println(numberOfThread); | |
return numberOfThread; | |
} | |
} | |
public static void main(String[] args) throws InterruptedException { | |
new Thread(new MyRunnable()).start(); | |
new Thread(new MyRunnable()).start(); | |
new Thread(new MyRunnable()).start(); | |
new Thread(new MyRunnable()).start(); | |
try { | |
Thread.sleep(1000); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
System.exit(0); | |
} | |
public static class MyRunnable implements Runnable { | |
@Override | |
public void run() { | |
try { | |
new WordLengthCallable().call(); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment