Description
Distributed task session is created for every task execution. It is defined by GridTaskSession ![]()
Session has 2 main features: attribute and checkpoint (see Checkpoint SPI for more details) management. Both, attributes and checkpoints, can be used from task itself and from the jobs belonging to this task. Session attributes and checkpoints can be set from any task or job methods. Session attribute and checkpoint consistency is fault tolerant and is preserved whenever a job gets failed over to another node for execution. Whenever task execution ends, all checkpoints saved within session with GridCheckpointScope.SESSION_SCOPE ![]()
![]()
The sequence in which session attributes are set is consistent across the task and all job siblings within it. There will never be a case when one job sees attribute A before attribute B, and another job sees attribute B before A. Attribute order is identical across all session participants. Attribute order is also fault tolerant and is preserved whenever a job gets failed over to another node.
Connected Tasks
Note that apart from setting and getting session attributes, tasks or jobs can choose to wait for a certain attribute to be set using any of the waitForAttribute(...) methods. Tasks and jobs can also receive asynchronous notifications about a certain attribute being set through GridTaskSessionAttributeListener ![]()
Imagine for example that you need to compress a very large file (let's say terabytes in size). To do that in grid environment you would split such file into multiple sections and assign every section to a remote job for execution. Every job would have to scan its section to look for repetition patterns. Once this scan is done by all jobs in parallel, jobs would need to synchronize their results with their siblings so compression would happen consistently across the whole file. This can be achieved by setting repetition patterns discovered by every job into the session. Once all patterns are synchronized, all jobs can proceed with compressing their designated file sections in parallel, taking into account repetition patterns found by all the jobs in the split. Grid task would then reduce (aggregate) all compressed sections into one compressed file. Without session attribute synchronization step this problem would be much harder to solve.
Session Injection
Session can be injected into a task or a job using IoC (dependency injection). See Resources Injection page for additional details.
Example
To see example on how to use distributed task session refer to HelloWorld Session Example.
