Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java synchronization between different JVMs

The project I am working on would trigger various asynchronous jobs to do some work. As I look into it more these asynchronous jobs are actually being run as separate JVMs (separate java processes). Does it mean I would not be able to use any of the following if I need to synchronize between these processes:

  • synchronized methods/blocks
  • any lock that implements java.util.concurrent.locks

Because it seems to me they are all thread-level?

Does Java provide support for IPC like semaphores between processes?

like image 629
tytchong Avatar asked May 16 '12 16:05

tytchong


1 Answers

That's right. You can not use any standard synchronization mechanisms because they are working into one JVM.

Solutions

  1. You can use file locks introduced in java 7.
  2. You can use synchronization via database entities.
  3. One of already implemented solutions like Terracota may be helpful
  4. Re-think your design. If you are beginner in java world try to talk in details with more experienced engineers. Your question shows that IMHO you are just on wrong way.
like image 183
AlexR Avatar answered Oct 01 '22 08:10

AlexR