简体   繁体   中英

How to get an instance of javax.imageio.spi.IIORegistry with proper scope

We have several webapps deployed to a WebSphere application server, where both applications use the ImageIO of standard Java, but one uses an additional Library to add more Readers/Writers.

The question is now, both applications use IIORegistry.getDefaultInstance() to get the instance of the service registry, and both applications seem to get the same instance. Internally this is related to AppContext.getAppContext() returning the same awt AppContext. Is there any proper way to have multiple WebSphere Applications using ImageIO of Java without having to care about both apps using the same libraries? Do I have to manually create an awt AppContext for my WebSphere Applications?

I believe the app context concept (the one used in the IIORegistry class, not to be confused with a web app context) was originally intended for applets (ie., multiple applets running in a single JVM in a browser). For web apps, this would also make sense, but I don't think it works that way. Also, I don't think there are any public API classes or methods related to creating or maintaining app contexts (it's all in the sun.awt.* packages), so manually creating contexts isn't recommended.

I've made a web context listener that will solve some of the issues with using ImageIO in web apps, ie. registering and unregistering web app "local" plugins, when the web app is loaded/unloaded (handling both discovery and removal of "stale" plugins). Unfortunately, this will not hide on web app's plugins from other web apps, if this is your intention (hard to tell from the question).

Having an AppContext per web app would probably be a cleaner approach, but as mentioned, the lack of public API and no "standard" way of doing it would make such a solution non-portable and thus undesirable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM