GridGain™ 3.6.0e
Enterprise Edition

Interface GridJob

All Superinterfaces:
All Known Implementing Classes:
CA, CAX, CO, COX, GridAbsClosure, GridAbsClosureX, GridCallable, GridEither, GridJobAdapterEx, GridJobOneWayAdapter, GridJobWrapper, GridOutClosure, GridOutClosureX, GridReducer, GridReducer2, GridReducer2X, GridReducer3, GridReducer3X, GridReducerX, GridRunnable, R1, R2, R3, RX1, RX2, RX3

public interface GridJob
extends Serializable

Defines executable unit for GridTask.


Grid job is an executable unit of GridTask. Grid task gets split into jobs when, Object) method is called. This method returns all jobs for the task mapped to their corresponding grid nodes for execution. Grid will then serialize this jobs and send them to requested nodes for execution. When a node receives a request to execute a job, the following sequence of events takes place:
  1. Job gets put on waiting list which is passed to underlying GridCollisionSpi SPI.
  2. The Collision SPI will decide one of the following scheduling policies:
  3. For activated jobs, an instance of distributed task session (see GridTaskSession) will be injected.
  4. System will execute the job by calling GridJob.execute() method.
  5. If job gets cancelled while executing then GridJob.cancel() method will be called. Note that just like with Thread.interrupt() method, grid job cancellation serves as a hint that a job should stop executing or exhibit some other user defined behavior. Generally it is up to a job to decide whether it wants to react to cancellation or ignore it. Job cancellation can happen for several reasons:
  6. Once job execution is complete, the return value will be sent back to parent task and will be passed into GridTask.result(GridJobResult, List) method via GridJobResult instance. If job execution resulted in a checked exception, then GridJobResult.getException() method will contain that exception. If job execution threw a runtime exception or error, then it will be wrapped into GridUserUndeclaredException exception.

Resource Injection

Grid job implementation can be injected using IoC (dependency injection) with grid resources. Both, field and method based injection are supported. The following grid resources can be injected: Refer to corresponding resource documentation for more information.


GridGain comes with convenience GridJobAdapterEx adapter that provides default empty implementation for GridJob.cancel() method and also allows user to set and get job argument, if there is one.

Distributed Session Attributes

Jobs can communicate with parent task and with other job siblings from the same task by setting session attributes (see GridTaskSession). Other jobs can wait for an attribute to be set either synchronously or asynchronously. Such functionality allows jobs to synchronize their execution with other jobs at any point and can be useful when other jobs within task need to be made aware of certain event or state change that occurred during job execution.

Distributed task session can be injected into GridJob implementation using @GridTaskSessionResource annotation. Both, field and method based injections are supported. Refer to GridTaskSession documentation for more information on session functionality.

Saving Checkpoints

Long running jobs may wish to save intermediate checkpoints to protect themselves from failures. There are three checkpoint management methods: Jobs that utilize checkpoint functionality should attempt to load a check point at the beginning of execution. If a non-null value is returned, then job can continue from where it failed last time, otherwise it would start from scratch. Throughout it's execution job should periodically save its intermediate state to avoid starting from scratch in case of a failure.

Wiki & Forum:



Method Summary
 void cancel()
          This method is called when when system detects that completion of this job can no longer alter the overall outcome (for example, when parent task has already reduced the results).
 Object execute()
          Executes this job.

Method Detail


void cancel()
This method is called when when system detects that completion of this job can no longer alter the overall outcome (for example, when parent task has already reduced the results). Job is also cancelled when GridFuture.cancel() is called.

Note that job cancellation is only a hint, and just like with Thread.interrupt() method, it is really up to the actual job instance to gracefully finish execution and exit.


Object execute()
               throws GridException
Executes this job.

GridException - If job execution caused an exception. This exception will be returned in GridJobResult.getException() method passed into GridTask.result(GridJobResult, List) method into task on caller node. If execution produces a RuntimeException or Error, then it will be wrapped into GridException.
Job execution result (possibly null). This result will be returned in GridJobResult.getData() method passed into GridTask.result(GridJobResult, List) method into task on caller node.

GridGain™ 3.6.0e
Enterprise Edition

GridGain - Real Time Big Data
Enterprise Edition, ver. 3.6.0e.13012012
2012 Copyright © GridGain Systems
Follow us:   Follow GridGain on Github Follow GridGain on Facebook Join GridGain User Group Follow GridGain on Twitter Follow GridGain on YouTube