#158 Enable timeout/onCancel for Callable/Runnable/POJO tasks

Laurent Cohen
Job / Task (2)
Laurent Cohen

From this forum thread: http://www.jppf.org/forums/index.php/topic,1679.0.html

The idea is to have the possiblitiy to use the task timeout and onCancel() functionalities for tasks that are not instances of JPPFTask (Task<E> in v3.0)
This includes:
- Callable tasks
- Runnable
- @JPPFRunnable annotated tasks
- Callable and Runnable tasks submitted with the JPPFExecutorService

Some possiblitlities come to mind:

- We could use interfaces to be implemented by the tasks:
public interface TimeoutAware {
JPPFSchedule getTimeoutSchedule();
void onTimeout();

public interface CancelAware {
void onCancel();

- We could check via reflection whether the functionality is implemented in the task, look for existence of methods getTimeoutSchedule(), onTimeout(), onCancel()

- We could use annotations: @GetTimeout, @OnTimeout, @OnCancel

One issue to deal with, is to provide the functionalities for JPPFExecutorService tasks without breaking the semantics of the java.util.concurrent.ExecutorService interface. Methods that apply to the executor itself could be ok,but not methods that modify the behavior of submitting tasks.


  • Laurent Cohen
    Laurent Cohen

    Another idea, suggested by the author of the same forum thread:

    To avoid the dependency on JPPF APIs for timeout, it would be good to have a way to set these sorts of properties via a config file on the client's side (or editing a property of something that can be easily accessed via the JPPFClient object).

    e.g. (not to be taken literally)

    JPPFClient client = new JPPFClient();
    client.getProperty("timeout").set("com.mypackage.MyTask", 5000L);

    and that means the code that initialises JPPF can deal with the JPPF properties, whereas the code that deals with the execution of the tasks only needs to know about J2SE Executors.

  • Laurent Cohen
    Laurent Cohen

    • assigned_to: nobody --> lolocohen
  • Laurent Cohen
    Laurent Cohen

    • status: open --> closed-fixed
  • Laurent Cohen
    Laurent Cohen

    For tasks added to a JPPFJob, these features are already available, since JPPFJob.addTask(...) returns a JPPFTask.
    We have added an API to allow configuring jobs and tasks submitted via a JPPFExecutorService.

    Changes committed to SVN trunk revision 2083