Preferences API working with multiple ClassLoaders

2019-09-05 07:57发布

问题:

i am currently working with the Preferences API to save settings in a Vaadin application. The application has 3 WebApps running on a Tomcat server. As i have learned, the Tomcat server has a ClassLoader for every module running on it but it is all running in one Virtual Machine.

Can anybody explain to me why Java Preferences are working on multiple ClassLoaders? I cannot find any source for this and i didn't find anything by debugging.

Thank you a lot.

回答1:

I have found the answer:

You get a Preferences-object by calling:

Preferences prefs = Preferences.userRoot().node("test);

Preferences and PreferencesFactory is loaded by the Bootstrap ClassLoader and so it is the same for every module (how ClassLoader work in Apache) and because the object is created in the PreferencesFactory it is not created in a WebApp context.