@SuppressWarnings("unchecked") private <U, V> V execute(U inputParameter, ProcessDescription<U, V> processDescription, Executor executorService) throws InterruptedException, ExecutionException { if (processDescription.getThreadType().equals(ThreadType.EXECUTOR)) { FutureTask<V> task = new FutureTask<V>(() -> { return processDescription.getFunction().apply(inputParameter); }); executorService.execute(task); return task.get(); } else { return ConcurrentUtils.runCallableAndWait(() -> { return processDescription.getFunction().apply(inputParameter); }); } }
public Worker<S> update() { return ConcurrentUtils.executeService(executor, ConcurrentUtils.createService(() -> { try { T id = ConcurrentUtils.runCallableAndWait(() -> get().getId()); S updatedData = crudService.getById(id); ConcurrentUtils.runAndWait(() -> set(updatedData)); return updatedData; } catch (Exception e) { throw new RuntimeException("TODO", e); } })); }