I am getting started on the executor service and i was wondering how i would call a function when a task is done.I have seen this function http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Future.html#isDone--
but i am not sure how i would wire it to call the function endoftheroad() in my code
This is my code
//import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
//import java.util.concurrent.Future;
//import java.util.concurrent.TimeUnit;
import java.util.*;
public class Pooler {
public static int add(int x, int y){
int c = x + y;
return c;
}
public static int endoftheroad(){
int the_end = 0;
return the_end;
}
public static void main(String args[]) {
ExecutorService service = Executors.newFixedThreadPool(10);
for (int i =0; i<100; i++){
Random randomno = new Random();
int value = randomno.nextInt();
service.submit(new Task(add(value,value)));
}
}
}
final class Task implements Runnable{
private int taskId;
public Task(int id){
this.taskId = id;
}
@Override
public void run() {
System.out.println("Task ID : " + this.taskId +" performed by "
+ Thread.currentThread().getName());
}
}