callback - Java executors: how to be notified, without blocking, when a task completes? -
Say I have a queue that I need to submit for an executable service. I want them to be processed at once.
- Take a job from the queue < / Li>
- Take another job from the queue ...
However, I'm trying to avoid blocking completely. If I have 10,000 such queues, whose tasks need to be processed at once, then I exit the stack space because most of them will be on blocked threads.
The work I want to do is submit a task and provide a call-back which is said to be completed on the task. I will use that call-back notification as a flag to send the next task (functional Java and JetLong apparently use such non-blocking algorithms, but I can not understand their code)
How can I do using JDK Java? My.util.concurrent, lack of writing your own executable service?
(The queue which feeds these functions, it can block itself, but there is a problem to face it later)
Define a callback interface to get the parameters you want to pass in the full notification, then open it at the end of the job. You can also type a general cover for Runnable tasks, and ExecutorService .
Runnable to apply callback task to class {private finals runnable tasks; Private last callback callback; Callback Tasks (Runnable Tasks, Callback Callbacks) {this.task = task; This.callback = callback; } Public Zero Run () {task.run (); Callback.complete (); }}
Comments
Post a Comment