[jboss-user] [Beginner's Corner] - Caching objects

David Bailey do-not-reply at jboss.com
Fri Dec 23 10:53:03 EST 2011


David Bailey [http://community.jboss.org/people/edwardpig] created the discussion

"Caching objects"

To view the discussion, visit: http://community.jboss.org/message/643075#643075

--------------------------------------------------------------
I've written a proof-of-concept session bean which wraps some legacy Java code.  The POC seems to be doing what we want it to do, and now it's time to make the bean production-ready.

Each instance of the bean loads configuration from an XML document.  There are several dozen XML documents available; the decision about which XML document is loaded depends on what we want the particular bean instance to do.

For the POC, I have simply dropped the XML documents in the servlet 'WEB-INF' directory.  At runtime, my POC servlet obtains the appropriate XML document from the ServletContext as an InputStream, and hands the InputStream to the session bean.  However, the XML documents in question can be up to a few MB in size, so we don't want to parse them repeatedly.  I think there are two requirements for how we would like to handle things:

1) Load and parse each XML document into an in-memory DOM tree at startup, and retain that DOM tree collection in memory 'forever' (until JBoss shuts down).

2) These XML documents rarely change --- in fact, they may *never* change --- but it should still be possible to update them if necessary.

So one question I have is: what is the best way to achieve the loading at startup and in-memory caching?  For my POC, I put a static Map in my bean which held references to each DOM, but that's not optimal because the XML isn't parsed at JBoss startup/bean deployment, and the static Map goes away if the bean ClassLoader is ever garbage collected.

Another question I have is: Where should the source XML documents reside?  I don't think delivering them in the WEB-INF directory of my web app is a good idea, because I want to be able to update the XML without redeploying the web app.  Perhaps I should parse each DOM tree, then store the whole tree as a CLOB in my database?

Suggestions are appreciated.
--------------------------------------------------------------

Reply to this message by going to Community
[http://community.jboss.org/message/643075#643075]

Start a new discussion in Beginner's Corner at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2075]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20111223/9b6cbd51/attachment.html 


More information about the jboss-user mailing list