Method call to Future.get() blocks. Is that really desirable?

Future offers you method isDone() which is not blocking and returns true if computation has completed, false otherwise. Future.get() is used to retrieve the result of computation. You have a couple of options: call isDone() and if the result is ready ask for it by invoking get(), notice how there is no blocking block indefinitely … Read more

How to make ThreadPoolExecutor’s submit() method block if it is saturated?

One of the possible solutions I’ve just found: public class BoundedExecutor { private final Executor exec; private final Semaphore semaphore; public BoundedExecutor(Executor exec, int bound) { this.exec = exec; this.semaphore = new Semaphore(bound); } public void submitTask(final Runnable command) throws InterruptedException, RejectedExecutionException { semaphore.acquire(); try { exec.execute(new Runnable() { public void run() { try { … Read more

Java executors: how to be notified, without blocking, when a task completes?

Define a callback interface to receive whatever parameters you want to pass along in the completion notification. Then invoke it at the end of the task. You could even write a general wrapper for Runnable tasks, and submit these to ExecutorService. Or, see below for a mechanism built into Java 8. class CallbackTask implements Runnable … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)