Task Execution With Special Requirements In Java

99 views Asked by At

Having to sink in my teeth into Java Executor Service I noticed that it falls flat for some of my requirements:

  1. I need to implement a small reactive system. So a Task can result in a new Task.
  2. The tasks schedule dynamically either as a reaction of an event (waiting for a token pool for instance) or by time.
  3. If a task dies I need to react accordingly so a task may be composed by different event methods or at least provide a listener service (like the Google guava lib)

I do not like the idea to implement it myself. But it is a event listener collection waiting for events to happen and immediately schedule tasks for this. Scheduling a job for a certain point in time is just also generating a timer event that is triggered by a waiting queue waiting for the nearest timer event to happen notify the framework and done.

So is there something around that provides this or a default way to use a Java Executor for this?

2

There are 2 answers

2
Derrops On

Use the java concurrency package which borrows concepts from a very up and coming framework called akka. That should be enough to do what you want, if not then use akka. I have an example here: Executing Dependent tasks in parallel in Java

EDIT: Yes correct in my example there was blocking on the get methods, simply use the

future.onComplete(new OnComplete<Object>() )

To remove any blocking.

0
Martin Kersten On

I found a final working solution for my self. Turned out that I just have to implement a special task and a simple executor of that task. The task can itself use any means to react and delay upon events. Waiting for a event is just a sequence of tasks or a event producer that creates tasks on behalf of an event. Simple as that.

But why building a scheduled executor using delays? That does makes no sense at all. No one ever wants to schedule tasks or events using a delay... .