Can anyone explain me the difference between Stateful job & non stateful job with a nice example?
Now, some additional notes about a job's state data (aka JobDataMap): A Job instance can be defined as "stateful" or "non-stateful". Non-stateful jobs only have their JobDataMap stored at the time they are added to the scheduler. This means that any changes made to the contents of the job data map during execution of the job will be lost, and will not seen by the job the next time it executes. You have probably guessed, a stateful job is just the opposite - its JobDataMap is re-stored after every execution of the job. One side-effect of making a job stateful is that it cannot be executed concurrently. Or in other words: if a job is stateful, and a trigger attempts to 'fire' the job while it is already executing, the trigger will block (wait) until the previous execution completes.
I am not sure what you have not understood. Let me put it again:
1. In case the job is stateless and you make changes to the JobDataMap the hanges will not be persisted to the JobStore by default and when the job is executed next time it will have the old JobDataMap instance. In case your job is Stateful job the changes to theJobDataMap will be persisted to the JobStore and so next time the job executes it will have the modified JobDataMap.
2. If you make your job Stateful, it implies that you will be changing the JobDataMap and if you are doing that you will want your changes to be visible when ever you execute the job next, thus the scheduler will only execute Stateful job once the previous running job is complete (thus stateful job can not be executed concurrently)
In quartz 2.0 the two notions of StatefulJob have been separated into two annotations: one that lets you specify non-concurrence of execution, and the other to specify the need to re-store the JobDataMap after execution.