开发者

static final's and multiple classloaders

I have a definition like this

public static final Object foo = Xyz.generateFoo(); 

And my appli开发者_JS百科cation is using multiple custom class loaders. How can I ensure that all classes see the same instance of foo?

Preferrably without resorting to external storage (ie System.Properties or file). Thanks.


Place a reference to the value in a class loaded by a common parent class loader.


Note that there is no way to ensure it if some of your custom classloaders violate the "check parent classloader first" rule (for example, as webapp classloaders do).

Otherwise you can place that field to the class loaded by parent classloader, as suggested by Tom Hawtin.


Is that you want the return of this Xyz.generateFoo(); to be same all the time or after assigning to the variable public static final Object foo = Xyz.generateFoo(); you want to access the same instance ever where.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜