简体   繁体   中英

How to synchronize two separate Java Applications when accessing a MySQL database

I want to have a Java Web App and a normal Java App that both have access to the same MySQL database using JDBC. The two are of course entirely independent so what i want is to find a way to synchronize them somehow, so that i can ensure that there will be no errors to the database access due to race conditions, but i don't know how to do that. Any suggestions?

Transactions. Pick the best isolation level of your transactions for your needs.

Most ORM solutions (hibernate, jpa) can use a 'version' column which will be checked when you attempt to write through to the database. If the version of the object you are trying to write is different than the version in the database then you are out of date and need to merge incoming changes first. It shouldn't be too hard to do something similar in JDBC.

事务(或某些DB事物)可能是最好的,但是如果在您的应用程序中无法正常工作,则可以设置一个虚拟文件并要求对其进行写访问作为您的锁。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM