<!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;">
    Re: EJB3 Session Bean Pool
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="http://community.jboss.org/people/robert.geisler">Robert Geisler</a> in <i>EJB3</i> - <a href="http://community.jboss.org/message/601123#601123">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>hi carlo,</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>thank you very much for uploading and commenting the sources.</p><p>i did not revise the code, yet, but i would like to discuss your statements...</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><strong>i) exception handling as logic</strong></p><p><strong><br/></strong></p><p>you told me not to use exception handling as logic because instantiation of exceptions "take[s] a large hit".</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>well, i guess, for a single execution an if/ else may be faster than throwing/ catching an exception. but please consider how often the exception is actually thrown: <em>only</em></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><ul><li>if the pool is empty (arraySize == 0) and get() is called or</li><li>the pool is full (arraySize == array.length) and release() is called.</li></ul><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>in contrast an if/ else would add an extra operation <em>whenever</em> get() or release() is executed.</p><p>that is why i excepted the exception handling logic to be the way to go. </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>what do you think?</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><strong>ii) LinkedList vs. array<br/></strong></p><p><strong><br/></strong></p><p>you proposed to use a LinkedList instead of cloning the array.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>i guess instantitation of arrays is more expensive than instantitation of a LinkedList.Entry, so again you may be right in case of a single execution. but please keep in mind that a LinkedList would be resized <em>whenever </em>get() or release() is called. LinkedList.add() creates a new LinkedList.Entry and links it to the first or last element of the list; LinkedList.remove() unlinks a LinkedList.Entry that later will be destroyed by gc.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>for an array, resizing occurs <em>only </em>if the pool is full (arraySize == array.length) and another element is released (and should be stored in the array). on get() no resizing (/ instantiation) is necessary. </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>so i guess than an array should beat a LinkedList -in case of frequent calls?</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><strong>iii) LRU</strong></p><p><strong><br/></strong></p><p>you said that the pool is always sorted by LRU (last recently used) and you are right, of course. </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>that means, on timeout not <em>all </em>elements in the pool have to be verified: i may remove the first timedout element and all elements beyond it.</p><p>so i suggest the following timeout algorithm: on timeout the current arraySize will be remembered as "timeout index". on next timeout this index will be used to find the first timedout element (at "timedout index"). if the element at timeout index is not timedout, timedout index has to be greater (otherwise less) than timeout index. all elements at and beyond timedout index will later be removed. in this way iteration is reduced to the minimum, unnecessary operations are avoided.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>do you confirm?</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>regards</p><p>robert</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/601123#601123">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in EJB3 at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2029">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>