Hi all,<br><br>It occurred to me that there is a performance penalty for loading MessageConveyor instances which can be mitigated with an extra cache like this<br><br><span style="font-family: courier new,monospace;">public class MessageConveyor implements IMessageConveyor {</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace; color: rgb(153, 0, 0);">    private static final Map&lt;Locale, MessageConveyor&gt; INSTANCES = new ConcurrentHashMap&lt;Locale, MessageConveyor&gt;();</span><br style="font-family: courier new,monospace;">

<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    private final Locale locale;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    final Map&lt;String, CAL10NResourceBundle&gt; cache = new ConcurrentHashMap&lt;String, CAL10NResourceBundle&gt;();</span><br style="font-family: courier new,monospace;">

<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    /**</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">     * Constructs an instance with a {@link Locale} associated with this</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">     * instance.</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">     * </span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">     * @param locale</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">     *            required locale</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">     */</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    MessageConveyor(Locale locale) {</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">        this.locale = locale;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    }</span><br style="font-family: courier new,monospace;">

<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    /**</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">     * Gets a cached instance associated with a particular {@link Locale}. If</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">     * the time taken to read the resource files is significant, the cached</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">     * instances will perform significantly better than simply creating a new</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">     * instance whenever it is needed.</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">     * </span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">     * @param locale</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">     *            required locale</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">     */</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    <span style="color: rgb(153, 0, 0);">public static MessageConveyor get(Locale locale) {</span></span><br style="font-family: courier new,monospace; color: rgb(153, 0, 0);">

<span style="font-family: courier new,monospace; color: rgb(153, 0, 0);">        MessageConveyor instance = INSTANCES.get(locale);</span><br style="font-family: courier new,monospace; color: rgb(153, 0, 0);"><span style="font-family: courier new,monospace; color: rgb(153, 0, 0);">        if (instance == null) {</span><br style="font-family: courier new,monospace; color: rgb(153, 0, 0);">

<span style="font-family: courier new,monospace; color: rgb(153, 0, 0);">            instance = new MessageConveyor(locale);</span><br style="font-family: courier new,monospace; color: rgb(153, 0, 0);"><span style="font-family: courier new,monospace; color: rgb(153, 0, 0);">            INSTANCES.put(locale, instance);</span><br style="font-family: courier new,monospace; color: rgb(153, 0, 0);">

<span style="font-family: courier new,monospace; color: rgb(153, 0, 0);">        }</span><br style="font-family: courier new,monospace; color: rgb(153, 0, 0);"><span style="font-family: courier new,monospace; color: rgb(153, 0, 0);">        return instance;</span><br style="font-family: courier new,monospace; color: rgb(153, 0, 0);">

<span style="font-family: courier new,monospace; color: rgb(153, 0, 0);">    }</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">...</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">}</span><br><br clear="all">Note that the constructor is now package-private - this breaks the API so will need to be agreed. It is not strictly necessary but desirable to encourage the most efficient use of Cal10n.<br>
<br>The internal cache (called &#39;cache&#39;) holds the actual resource bundles and avoids them being repeatedly read from disk.  Previously, this cache would be dropped every time an instance
was no longer referenced. The next time the same locale was required, a
new instance would be needed, also needing the same files to be read from
disk again.<br><br>Now, the new static INSTANCES cache holds the instances, each of which holds its cache containing the resource bundles that were read from disk.  There is a small penalty in consulting the INSTANCES cache but this should be no worse than re-reading the files (and probably much better).<br>

<br>I&#39;ve attached a patch, which replaces the one I sent on the 14th.<br><br>Regards,<br>Rick<br>-- <br>Big Bee Consultants Limited : Registered in England &amp; Wales No. 6397941<br>Registered Office: 71 The Hundred, Romsey, Hampshire, SO51 8BZ<br>