javamultithreadingjava-6

Future tasks in Java 1.6


In Java 1.7, we can have future tasks where the rest of the processes of obj will continue in new threads without waiting for the results of other.

private static ExecutorService executorService 
  = Executors.newFixedThreadPool(1);

public void update(MyObject obj) {
    executorService.execute(new FutureTask<>(new MyFutureTask(obj)));  
}

Is there any way to do something similar to this in Java 1.6?


Solution

  • FutureTask<V> introduced in java 1.5, you can use it in java 1.6 without any doubt :) .

    Check the documentation