How jobs are assigned to executors in Spark Streaming?

Actually, in the current implementation of Spark Streaming and under default configuration, only job is active (i.e. under execution) at any point of time. So if one batch’s processing takes longer than 10 seconds, then then next batch’s jobs will stay queued. This can be changed with an experimental Spark property “spark.streaming.concurrentJobs” which is by … Read more

ThreadPoolExecutor Block When its Queue Is Full?

In some very narrow circumstances, you can implement a java.util.concurrent.RejectedExecutionHandler that does what you need. RejectedExecutionHandler block = new RejectedExecutionHandler() { rejectedExecution(Runnable r, ThreadPoolExecutor executor) { executor.getQueue().put( r ); } }; ThreadPoolExecutor pool = new … pool.setRejectedExecutionHandler(block); Now. This is a very bad idea for the following reasons It’s prone to deadlock because all the … Read more

asyncio: Is it possible to cancel a future been run by an Executor?

In this case, there is no way to cancel the Future once it has actually started running, because you’re relying on the behavior of concurrent.futures.Future, and its docs state the following: cancel() Attempt to cancel the call. If the call is currently being executed and cannot be cancelled then the method will return False, otherwise … Read more

ThreadPoolExecutor Block When Queue Is Full?

In some very narrow circumstances, you can implement a java.util.concurrent.RejectedExecutionHandler that does what you need. RejectedExecutionHandler block = new RejectedExecutionHandler() { rejectedExecution(Runnable r, ThreadPoolExecutor executor) { executor.getQueue().put( r ); } }; ThreadPoolExecutor pool = new … pool.setRejectedExecutionHandler(block); Now. This is a very bad idea for the following reasons It’s prone to deadlock because all the … Read more

Java Executors: how can I set task priority?

Currently the only concrete implementations of the Executor interface are the ThreadPoolExecutor and the ScheduledThreadpoolExecutor Instead of using the utility / factory class Executors, you should create an instance using a constructor. You can pass a BlockingQueue to the constructors of the ThreadPoolExecutor. One of the implementations of the BlockingQueue, the PriorityBlockingQueue lets you pass … 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