Recently I came across a excellent feature of Spring framework,Just wanted to share with you all.
You must be aware of scheduling framework Quartz.
Quartz is a full-featured, open source job scheduling system that can be integrated with, or used along side virtually any J2EE or J2SE application.
I was working on a spring application ,all my business services are spring beans ,my transaction manager is "org.springframework.jdbc.datasource.DataSourceTransactionManager" which is local transaction manager,as my application is not in demand of JTA or any distributed transaction.
Now comes a trick ,when I come across following scenario
Suppose I have a business service which does following
- Insert a record in DB
- Schedules a job in Quartz
- Updates some record in DB
- If update in step 3 fails ,I want to rollback steps 1,2
- If Step 2 fails ,I want step 1 to rollback
As expcted ,Solution to this problem is provided by none other than spring,Thanks to Juergen Hoeller.
Spring comes with
org.springframework.scheduling.quartz.LocalDataSourceJobStore which is extension to Quartz JobStoreCMT
Now you just need to cnfigure your job store as below
org.quartz.jobStore.class =
org.springframework.scheduling.quartz.LocalDataSourceJobStoreNow ,Operations performed by this JobStore will properly participate in any kind of Spring-managed transaction, as it uses Spring's DataSourceUtils connection handling methods that are aware of a current transaction.
How easily spring solves this problem shows ,springs capability to be an enterprise application framework......
1 comment:
getting exception
'dataSource' property must be set on SchedulerFactoryBean
Post a Comment