I have a very basic question about wait-notify mechanism in Java. I know that we can synchronize two different threads by using this, however, do these threads need to be running in the same process? What if there are two threads running in two different processes? Would wait-notify approach still work?
Wait-notify won't work for threads running in different processes.
Suppose process A allocated memory of 0x1000-0x2000, and is synchronizing on a lock 0x1200
Process B allocates memory of 0x3000-0x4000. It can't possibly get access to 0x1200, can it...
Your best synchronization approaches at that point will be
When you start the JVM process, every thread you create and the memory you use belong to that JVM instance and none other.
When you launch another JVM instance, these two instances do not share memory resources. Hence wait/notify (or any other object for that matter) will only be accessible for threads belonging to that instance of JVM and not other process.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With