Coordinating preferences access across multiple application instances

suggest change

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 the application runs in multiple instances on one system, coordinate Preferences access between those JVMs with sync() on a node. sync() writes this node's pending changes to the backing store and reloads changes that other JVMs have already committed:

// A single-instance application does not need sync() to see other JVMs.
// sync() still forces a write of pending local changes.
try {
    preferences.sync();
} catch (BackingStoreException e) {
    // Deal with any errors while saving the preferences to the backing storage
    e.printStackTrace();
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents