You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Sid Sidney <pv...@yahoo.com> on 2009/06/14 14:28:46 UTC

using static helper classes within servlets

 
    
            
            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? 


      

Re: using static helper classes within servlets

Posted by Pid <p...@pidster.com>.
Leon Rosenberg wrote:
> Hello,
> 
> On Sun, Jun 14, 2009 at 7:01 PM, Jonathan
> Mast<jh...@gmail.com> wrote:
>> 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;
>>     }
>> }
> 
> This is clearly the worst possible variant of doing it. Since
> getSomeBean is called ALL the time and each call is synchronized you
> are virtually giving up your concurrency and lining up all requests.
> This will cause you serious headache as soon as the site becomes
> decent traffic.
> 
> There are at least two better ways to do it, static initizialization
> and double checked locking (later only on post 1.5 vms).
> 1.
>  class BeanBag {
>      private static final SomeBean someBean = new SomeBean();
> 
>       public static  SomeBean getSomeBean() {
>              return someBean;
>      }
>  }
> 
> The difference is that the initialization happens at the loading time
> of the class which is guaranteed be the jvm to be synchronized
> (executed only by one thread) so there will be only one instance of
> someBean and it will be available at first call to getSomeBean.

This variation is useful, if the goal is the Singleton pattern.

 http://en.wikipedia.org/wiki/Initialization_on_demand_holder_idiom

p


> 2. DLC - double checked locking, this is a very powerful but
> hot-discussed pattern, useful if the instantiation of someBean is
> really costly and you want to postpone it until it really needed. In
> this case:
>  class BeanBag {
>      private static volatile SomeBean someBean = null;
> 
>   public static  SomeBean getSomeBean() {
> 	if (someBean==null){
> 		synchronized(BeanBag.class){
> 			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.
> 
> yet :-)
> 
> regards
> Leon
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: using static helper classes within servlets

Posted by Leon Rosenberg <ro...@googlemail.com>.
Hello,

On Sun, Jun 14, 2009 at 7:01 PM, Jonathan
Mast<jh...@gmail.com> wrote:
> 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;
>     }
> }

This is clearly the worst possible variant of doing it. Since
getSomeBean is called ALL the time and each call is synchronized you
are virtually giving up your concurrency and lining up all requests.
This will cause you serious headache as soon as the site becomes
decent traffic.

There are at least two better ways to do it, static initizialization
and double checked locking (later only on post 1.5 vms).
1.
 class BeanBag {
     private static final SomeBean someBean = new SomeBean();

      public static  SomeBean getSomeBean() {
             return someBean;
     }
 }

The difference is that the initialization happens at the loading time
of the class which is guaranteed be the jvm to be synchronized
(executed only by one thread) so there will be only one instance of
someBean and it will be available at first call to getSomeBean.

2. DLC - double checked locking, this is a very powerful but
hot-discussed pattern, useful if the instantiation of someBean is
really costly and you want to postpone it until it really needed. In
this case:
 class BeanBag {
     private static volatile SomeBean someBean = null;

  public static  SomeBean getSomeBean() {
	if (someBean==null){
		synchronized(BeanBag.class){
			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.

yet :-)

regards
Leon

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: [OT] using static helper classes within servlets

Posted by David Blevins <da...@visi.com>.
On Jun 15, 2009, at 9:32 AM, Christopher Schultz wrote:

> On 6/14/2009 5:43 PM, David Blevins wrote:
>> Regardless of that choice we
>> will still handle sychronization of instantiation, so
>> double-check-locking or other things will not be necessary.
>
> NB: DCL does not work in Java. Period.
>
> http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html
>
> There are cases where you /can/ make it work, but let's face it: most
> programmers simple cannot be trusted to do it properly. Also, the
> techniques are very sensitive to JVM level, etc. so you'd need to  
> have a
> different implementation depending on which JVM you were running. Yuk.

Chris, I was referring to the EJB 3.1 Singleton bean type which would  
free him up from having to write that complicated code you mention.

-David


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: [OT] using static helper classes within servlets

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Christopher Schultz [mailto:chris@christopherschultz.net]
> Subject: Re: [OT] using static helper classes within servlets
> 
> NB: DCL does not work in Java. Period.

While that statement was true for 1.4 and prior JVMs, 1.5 actually made DCL work.

> http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html

Note that the majority of the above was written prior to the development of JSR 133, let alone its implementation; my reading of JSR 133 indicates that the volatile keyword is no longer required, due to the requirement of flushing any internally cached values at the entrance to a synchronized block.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.


Re: [OT] using static helper classes within servlets

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Tim,

On 6/15/2009 12:43 PM, Tim Funk wrote:
> correction: The double checked idiom was "fixed" in java5. The variable
> which is checked needs to be declared as volatile. The link states that
> at the bottom.

...which is why I said:

>> There are cases where you /can/ make it work, but let's face it: most
>> programmers simple cannot be trusted to do it properly. Also, the
>> techniques are very sensitive to JVM level, etc. so you'd need to have a
>> different implementation depending on which JVM you were running. Yuk.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAko2yWoACgkQ9CaO5/Lv0PDHOgCfarmCJhzzjKfeC7tF4tTT2eF6
9DoAoJP2gROiP3B+hvnRseGnttrPfVcP
=XWKy
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: [OT] using static helper classes within servlets

Posted by Tim Funk <fu...@apache.org>.
correction: The double checked idiom was "fixed" in java5. The variable 
which is checked needs to be declared as volatile. The link states that 
at the bottom.

-Tim

Christopher Schultz wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> David,
>
> On 6/14/2009 5:43 PM, David Blevins wrote:
>   
>> Regardless of that choice we
>> will still handle sychronization of instantiation, so
>> double-check-locking or other things will not be necessary.
>>     
>
> NB: DCL does not work in Java. Period.
>
> http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html
>
> There are cases where you /can/ make it work, but let's face it: most
> programmers simple cannot be trusted to do it properly. Also, the
> techniques are very sensitive to JVM level, etc. so you'd need to have a
> different implementation depending on which JVM you were running. Yuk.
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: [OT] using static helper classes within servlets

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

David,

On 6/14/2009 5:43 PM, David Blevins wrote:
> Regardless of that choice we
> will still handle sychronization of instantiation, so
> double-check-locking or other things will not be necessary.

NB: DCL does not work in Java. Period.

http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html

There are cases where you /can/ make it work, but let's face it: most
programmers simple cannot be trusted to do it properly. Also, the
techniques are very sensitive to JVM level, etc. so you'd need to have a
different implementation depending on which JVM you were running. Yuk.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAko2d5gACgkQ9CaO5/Lv0PAUmACgqYFB8fvkL0fts8Ot/KAOnwL9
mWYAoKBFHEGfi0oWk1WXtAdcVW69G1hD
=I+hs
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: using static helper classes within servlets

Posted by David Blevins <da...@visi.com>.
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.

   http://openejb.apache.org/3.0/singleton-example.html
   http://openejb.apache.org/singleton-ejb.html

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.


-David


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
> http://openejb.apache.org/3.0/examples.html
>
> 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: jhmast.developer@gmail.com
>> To: users@tomcat.apache.org
>>
>> 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 <pv...@yahoo.com>  
>> 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®.
> http://windowslive.com/Tutorial/Hotmail/QuickAdd?ocid=TXT_TAGLM_WL_HM_Tutorial_QuickAdd_062009


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: using static helper classes within servlets

Posted by Martin Gainty <mg...@hotmail.com>.
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
http://openejb.apache.org/3.0/examples.html

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: jhmast.developer@gmail.com
> To: users@tomcat.apache.org
> 
> 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 <pv...@yahoo.com> 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®. 
http://windowslive.com/Tutorial/Hotmail/QuickAdd?ocid=TXT_TAGLM_WL_HM_Tutorial_QuickAdd_062009

Re: using static helper classes within servlets

Posted by Jonathan Mast <jh...@gmail.com>.
Sid, what everyone is saying about my first reply to your post is correct,
that code sample unnecessarily uses synchronization to achieve what static
initialize could do less expensively.  I wrote class awhile ago with paying
much attention to the costs of synchronization.

private static final SomeBean someBean = new SomeBean();

public static getSomeBean() {
   return someBean;
}

is a much better approach to the issue you are having and I will myself
transition to this pattern the shortly.

I should add that in my webapp, most references to Beans served by the lazy
BeanBag are themselves statically initialized (because static methods make
use of them) so this has probably shielded me from the costs of the accessor
methods being synchronized.


On Mon, Jun 15, 2009 at 1:25 PM, Caldarale, Charles R <
Chuck.Caldarale@unisys.com> wrote:

> > From: Christopher Schultz [mailto:chris@christopherschultz.net]
> > Subject: Re: using static helper classes within servlets
> >
> > You can get a significant performance improvement by doing this
> > instead:
> >
> > private static final SomeBean someBean = new SomeBean();
> >
> > public static getSomeBean() {
> >   return someBean;
> > }
> >
> > Of course, if you're going for delayed/lazy instantiation, you're not
> > going to get it, but you at least drop the penalty for synchronization.
>
> Using an initialize-on-demand holder class permits lazy instantiation:
>
> class MyClass {
>  ...
>  private static class LazySomethingHolder {
>    public static final Something something = new Something();
>  }
>  ...
>  public static Something getInstance() {
>    return LazySomethingHolder.something;
>  }
>  ...
> }
>
> The LazySomethingHolder will be loaded - but not initialized - when MyClass
> is loaded.  Initialization will occur only when MyClass.getInstance() is
> invoked.  The necessary synchronization during initialization is all handled
> internally by the JVM.
>
>  - Chuck
>
>
> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
> MATERIAL and is thus for use only by the intended recipient. If you received
> this in error, please contact the sender and delete the e-mail and its
> attachments from all computers.
>
>

RE: using static helper classes within servlets

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Christopher Schultz [mailto:chris@christopherschultz.net]
> Subject: Re: using static helper classes within servlets
> 
> You can get a significant performance improvement by doing this
> instead:
> 
> private static final SomeBean someBean = new SomeBean();
> 
> public static getSomeBean() {
>   return someBean;
> }
> 
> Of course, if you're going for delayed/lazy instantiation, you're not
> going to get it, but you at least drop the penalty for synchronization.

Using an initialize-on-demand holder class permits lazy instantiation:

class MyClass {
  ...
  private static class LazySomethingHolder {
    public static final Something something = new Something();
  }
  ...
  public static Something getInstance() {
    return LazySomethingHolder.something;
  }
  ...
}

The LazySomethingHolder will be loaded - but not initialized - when MyClass is loaded.  Initialization will occur only when MyClass.getInstance() is invoked.  The necessary synchronization during initialization is all handled internally by the JVM.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.


Re: using static helper classes within servlets

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jonathan,

On 6/14/2009 1:01 PM, Jonathan Mast wrote:
> class BeanBag {
>       private static SomeBean someBean = null;
> 
>       public static synchronized getSomeBean() {
>              if (someBean == null) someBean = new SomeBean();
>              return someBean;
>      }
> }

You can get a significant performance improvement by doing this instead:

private static final SomeBean someBean = new SomeBean();

public static getSomeBean() {
  return someBean;
}

Of course, if you're going for delayed/lazy instantiation, you're not
going to get it, but you at least drop the penalty for synchronization.

> I have now numerous Servlets, JSPs and POJOs that use BeanBag to obtain
> singleton instances of my beans.  Its worked great for me.

Remember that object instantiation isn't really a big deal. If you have
complex object /initialization/, then it may be worth using a
"singleton" (virtually impossible in the webapp realm unless you are
very careful), flyweight, pool, or other pattern to re-use objects yet
still retain a high degree of throughput.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAko2dsMACgkQ9CaO5/Lv0PD2/ACggkuH76invGEJOWIV2JArvNrG
W3oAmQEB3nzbXTsyE44NOTZftOfDjl7N
=xDwO
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: using static helper classes within servlets

Posted by Jonathan Mast <jh...@gmail.com>.
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 <pv...@yahoo.com> 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?
>
>
>