tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sid Sidney <>
Subject Re: using static helper classes within servlets
Date Mon, 15 Jun 2009 00:17:59 GMT
Thanks David, but we are stuck with Struts and EJB 2.1 at the moment. 

--- On Sun, 6/14/09, David Blevins <> wrote:

From: David Blevins <>
Subject: Re: using static helper classes within servlets
To: "Tomcat Users List" <>
Date: Sunday, June 14, 2009, 5:43 PM

Hey all,

If the goal is to ensure that only one instance is in the webapp, I'd recommend the new EJB
3.1 bean type @Singleton which is supported in OpenEJB 3.1 and 3.1.1.

Instantiation can be done at startup or lazily.  All method access synchronization is handled
for you via @ConcurrencyManagement(CONTAINER) or by you @ConcurrencyManagement(BEAN).  Regardless
of that choice we will still handle sychronization of instantiation, so double-check-locking
or other things will not be necessary.


On Jun 14, 2009, at 11:19 AM, Martin Gainty wrote:

> that would be the simplest solution
> i *think* the OP wanted a complete EJB jar implementation (using either annotations and
or ejb-jar.xml)
> which can be accomplished with OpenEJB except he would need to know the type vis-a-vis
Stateless/Stateful Local/Remote beforehand
> thanks,
> Martin
> ______________________________________________
> Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité
> Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so
bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer
Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und
entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails
koennen wir keine Haftung fuer den Inhalt uebernehmen.
> Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire
prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe
quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information
seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les
email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune
responsabilité pour le contenu fourni.
>> Date: Sun, 14 Jun 2009 13:01:31 -0400
>> Subject: Re: using static helper classes within servlets
>> From:
>> To:
>> I've not done anything with EJBs and I'm not sure what exactly you mean by
>> static "properties".  I have however dealt with reducing instantiations in
>> servlets.  I simply created a BeanBag class with static methods to each one
>> of my beans; these are not "proper" beans, but where simply objects that
>> were formerly used in JSP via the jsp:useBean directive.
>> Here is the general pattern:
>> class BeanBag {
>>      private static SomeBean someBean = null;
>>      public static synchronized getSomeBean() {
>>             if (someBean == null) someBean = new SomeBean();
>>             return someBean;
>>     }
>> }
>> I have now numerous Servlets, JSPs and POJOs that use BeanBag to obtain
>> singleton instances of my beans.  Its worked great for me.
>> On Sun, Jun 14, 2009 at 8:28 AM, Sid Sidney <> wrote:
>>>           HI,
>>> In my web app, my servlets user several delegate classes that connect
>>> to ejbs (session beans.)  I was thinking
>>> about putting these delegates into a helper class as static properties.
>>> That way my servlets can just reference the same delegates. I
>>> don't want to have to create a new instance of a delegate with every
>>> request that my servlet(s) handles.
>>> However, I'm wondering if this will cause synchronization issues with
>>> multiple requests being handled, as our site handles a heavy load of
>>> requests. Any suggestions would be appreciated?
> _________________________________________________________________
> Insert movie times and more without leaving Hotmail®.

To unsubscribe, e-mail:
For additional commands, e-mail:

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message