Java Language Preferences Coordinating preferences access across multiple application instances

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

All instances of Preferences are always thread-safe across the threads of a single Java Virtual Machine (JVM). Because Preferences can be shared across multiple JVMs, there are special methods that deal with synchronizing changes across virtual machines.

If you have an application which is supposed to run in a single instance only, then no external synchronization is required.

If you have an application which runs in multiple instances on a single system and therefore Preferences access needs to be coordinated between the JVMs on the system, then the sync() method of any Preferences node may be used to ensure changes to the Preferences node are visible to other JVMs on the system:

// Warning: don't use this if your application is intended
// to only run a single instance on a machine once
// (this is probably the case for most desktop applications)
try {
    preferences.sync();
} catch (BackingStoreException e) {
    // Deal with any errors while saving the preferences to the backing storage
    e.printStackTrace();
}


Got any Java Language Question?