Hi all,
I am new to Spring transaction management. My business requirement is this:
I have a method, say updateData in dao layer. This method will do series of postgres operations and return a map which will hold status, errorcode, errormessage as keys and appropriate values for them. When there is huge data input , I want to split the input data and execute this method[updateData] in different threads. Even if one thread fails all other threads also should rollback. Currently only the thread which fails is rolled back. All other threads are getting committed. Can someone help me how to manage the transaction for this multithreaded scenario.
This is my code setup:
1. I use annotation-driven transaction management for updateData [@Transactional(propagation=Propagation.REQUIRED, rollbackFor=Exception.class)]. Code looks something like this:
2. I use ExecutorService to spawn threads and get the Future objects to check for the results. Code looks something like
3. I use org.springframework.jdbc.core.JdbcTemplate and org.springframework.jdbc.datasource.DataSourceTransactionManager for executing queries. For example, like this: