I have a Callable<String> . I want to run it periodically through ScheduledExecutorService.scheduleAtFixedRate() and get a list of all the rows that were returned by .call() calls on my called. Since scheduleAtFixedRate does not accept Callable ( Runnable s only), I need to deploy a custom Runnable that wraps my Callable , something like these lines:
final Callable<String> myCallable = ....; final ConcurrentLinkedQueue<String> results = new ConcurrentLinkedQueue<String>(); Runnable r = new Runnable() { @Override public void run() { try { results.add(myCallable.call()); } catch (Exception e) { results.add(null);
Naturally, I would not want to roll back my own things (especially in multi-threaded code), so I think there is a JDK class that does this kind of aggregation?
java java.util.concurrent
Itay maman
source share