What is the technical reason for the single JVM restriction? #361
-
Greetings, I'm a Java developer and student, and also completely new to MicroStream. As someone who worked on multiple applications accessing third party databases, I find this technology very interesting. I'm currently researching for my master thesis (which will include MicroStream in some way) and discovered a restriction in your FAQ regarding the usage of multiple JVM processes: doc. The description states that some rules must be guarded to avoid inconsistency. My questions are:
Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi, The rule is that only a single JVM/ single PersistenceManager can write to the persistent store. When you have multiple instances pointing to the same directory with data, they both start writing independently from each to it and will corrupt the storage. The data on the disk will not match the Java objects in memory anymore. When you have multiple threads modifying the object graph that is assigned the root for MicroStream, you need to apply concurrency guarantees (unless your changes are atomic like assigning a new value for a String variable). You can make use of the ReentrantReadWriteLock class of Java and the readLock and writeLock methods, to make sure that no other threads are reading the data when you make changes. When you have multiple instances, you must assign a 'master' and synchronize the data to all instances using for example the communication support we have added (https://docs.microstream.one/manual/communication/index.html) Hope this clarifies your questions. |
Beta Was this translation helpful? Give feedback.
Hi,
The rule is that only a single JVM/ single PersistenceManager can write to the persistent store. When you have multiple instances pointing to the same directory with data, they both start writing independently from each to it and will corrupt the storage. The data on the disk will not match the Java objects in memory anymore.
When you have multiple threads modifying the object graph that is assigned the root for MicroStream, you need to apply concurrency guarantees (unless your changes are atomic like assigning a new value for a String variable). You can make use of the ReentrantReadWriteLock class of Java and the readLock and writeLock methods, to make sure that no other threads are …