<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">
<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>
                                <td>
                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>
                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px; -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
Caching objects
</h3>
<span style="margin-bottom: 10px;">
created by <a href="http://community.jboss.org/people/edwardpig">David Bailey</a> in <i>Beginner's Corner</i> - <a href="http://community.jboss.org/message/643075#643075">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">
<div class="jive-rendered-content"><p>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.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>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.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>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:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>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).</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>2) These XML documents rarely change --- in fact, they may <strong>never</strong> change --- but it should still be possible to update them if necessary.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>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.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>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?</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Suggestions are appreciated.</p></div>
<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
<p style="margin: 0;">Reply to this message by <a href="http://community.jboss.org/message/643075#643075">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in Beginner's Corner at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2075">Community</a></p>
</div></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>