Missing element in WeakRefVFSCache
alesj Nov 4, 2008 11:23 AMJust something I noticed, which I didn't expect.
I'm running JBossAS with WeakRefVFSCache: -Djboss.vfs.cache=org.jboss.virtual.plugins.cache.WeakRefVFSCache
Hence every VFSContext that doesn't have strong ref should be GCed.
In order to prevent some of them from being GCed too soon,
I've added the following bean:
public class PreInitializeVFSContexts { private Logger log = Logger.getLogger(PreInitializeVFSContexts.class); private List<URL> initializedVFSContexts; private boolean holdReference; private List<VFS> references; /** * Start initializer. * * @throws Exception for any exception */ public void start() throws Exception { if (initializedVFSContexts != null && initializedVFSContexts.isEmpty() == false) { if (holdReference) references = new ArrayList<VFS>(); for (URL url : initializedVFSContexts) { VFS vfs = VFS.getVFS(url); log.debug("Initialized Virtual File: " + vfs.getRoot()); if (holdReference) { references.add(vfs); } } } } /** * Clear possible references. */ public void stop() { if (references != null) references.clear(); } /** * Get VFS references. * * @return the VFS references */ public List<VFS> getReferences() { return references; } /** * Set URLs that need to be initialized before anything else. * * @param initializedVFSContexts the URLs to be initialized */ public void setInitializedVFSContexts(List<URL> initializedVFSContexts) { this.initializedVFSContexts = initializedVFSContexts; } /** * Should we hold the reference to initialized VFSs. * * @param holdReference the hold reference flag */ public void setHoldReference(boolean holdReference) { this.holdReference = holdReference; } }
So, if you mark this bean as holdReference, it's gonna put VFS into List,
hence keeping the strong ref; VFS --> VFSContext
See JBossAS/initialize.xml:
<bean name="JBossVFSInitializer" class="org.jboss.virtual.plugins.cache.PreInitializeVFSContexts"> <property name="initializedVFSContexts"> <list elementClass="java.net.URL"> <value>${jboss.lib.url}</value> <value>${jboss.shared.lib.url}</value> <value>${jboss.server.lib.url}</value> </list> </property> <property name="holdReference">true</property> </bean>
But when inspecting jmx-console VFSCacheStatistics,
I'm missing jboss.server.lib.url (it's real value) in VFSContext list.
Where did I go wrong? :-)