How to synchronize a java method called by PL/SQL

守給你的承諾、 提交于 2019-12-02 07:09:48

I have no idea how the JVM inside the Oracle DB is implemented, but since (at least in some common configurations) every database connection gets its own server process, then if a separate JVM is embedded into each of those, a synchronized block won't do you much good. You'd need to use database locks.

  1. Assuming that the calls to the Java static method are done within the same classloader, then synchronized is all you need.

  2. Your logging may be faulty. How exactly are you logging?

  3. Your statement about the database lookup being "time consuming" is not convincing. Databases tend to cache data, for example.

In a nutshell: if, by your definition, an "atomic operation" is a combination of lookup + insert, then you should "synchronize" over both. Acquiring a database lock seems like a reasonable way to go about it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!