Skip to content

Instantly share code, notes, and snippets.

@AndrienkoAleksandr
Created August 10, 2014 17:41
Show Gist options
  • Save AndrienkoAleksandr/b78b0e4e17b9c4facf90 to your computer and use it in GitHub Desktop.
Save AndrienkoAleksandr/b78b0e4e17b9c4facf90 to your computer and use it in GitHub Desktop.
callable without ExecutorService
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