BAEL-612: Single and multi threaded Future usage.

This commit is contained in:
Felipe Reis
2017-01-25 21:57:36 -02:00
parent cc7d5ba3fc
commit f36d7f1ac2
2 changed files with 118 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
package com.baeldung.concurrent.future;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
public class SquareCalculator {
private final ExecutorService executor;
public SquareCalculator(ExecutorService executor) {
this.executor = executor;
}
public Future<Integer> calculate(Integer input) {
return executor.submit(new Callable<Integer>() {
@Override
public Integer call() throws Exception {
Thread.sleep(1000);
return input * input;
}
});
}
}