Question

I have two application First Application will persist into a database in a while loop , the loop will end after a long time (say 10-15 minutes). But The second application needs the data that the first application has already persisted in the database , The second application cannot wait for the first application to finish .It will start just after the first application has started running. I have used an EntityManager.flush() in the first application hoping that the first application will immediately synch the data with the database. So that the second application which is in a different transaction can start working with data .

This is not working , what is the purpose of flush() method than and how can i solve my problem ? Please help !!

Was it helpful?

Solution

flush() writes all the pending changes to the database. It executes insert, update and delete statements. It's (by default) automatically called before committing the transaction.

But just because you flushed doesn't mean other transactions will see the changes. This depends on the transaction isolation level, which, in most databases, is READ_COMMITTED. Transactions run in isolation from each other (the I in ACID). So, if your isolation level is READ_COMMITTED, the transaction in the second app won't see any change done in the transaction of the first app until this transaction has committed.

OTHER TIPS

It sounds as if you should split the work of the first application into separate transactions. Changes are normally only visible to other transaction after commit (as explained by JB Nizet. You could change that, but you shouldn't).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top