2

The problem: I'm preparing single-instance application to become multi-instance. There are a lot of Lock usages (from java.util.concurrent.locks package) to synchronize access to some resources (external files on other server). Now for synchronizing ReentrantLock implementation of Lock is used.

To share locks between instances I want to use PostgreSQL database table which is already connected via JDBC. Since all consumers uses only Lock interface (not uses ReentrantLock class directly) I want to replace Lock implementation with Lock based on database table.

What is the correct way to implement Lock based on database table? Or maybe any standard java.util.concurrent.locks.Lock implementation based on JDBC exists?

UPDATE: I'm not looking for table locking mechanism (like in Table lock in PostgreSQL question), I need Lock implementation to use it in-code, not in SQL.

Kirill
  • 7,580
  • 6
  • 44
  • 95
  • If there is some specific reason for using the synchronization using the jdbc or you want to use synchronization in multi instance scenarios – Dinesh Oct 02 '18 at 10:15
  • @Dinesh no, I can use any multi-instance synchronization, but JDBC based would be more desirable, because it's the only fast and shared resource for all instance, which is already connected. – Kirill Oct 02 '18 at 10:19

0 Answers0