The overhead of JMS varies greatly depending on how it is used: acknowledgment modes, subscription durability etc. Guaranteed delivery (necessary for some operations) is likely to be slow.
In some situations there may be simpler, lighter-weight alternatives to JMS, using thread creation (allowed outside the EJB container) or the Observer design pattern without JMS (that is, notifying listeners - who may perform actions in the calling thread or in a new thread - using an ordinary Java implementation, and not JMS).
The Observer design pattern implemented this way will create much less overhead than JMS.
However, whether it works in a clustered environment depends on what listeners must do.
The server provides cluster-wide support for JMS.
We can use this altenative approach to JMS:
-
When the application does not run in a cluster and is never likely to.-
When it doesn't matter if all event processing occurs on the server on which the event was generated.You cannot syncronize a static variable. It is always better if you modify your variables using set/get methods. Once you syncronize your set method your variable would be thread safe.I saw people using synchonize blocks for servlet instance variables instead of maintaining local variables. Since servlet is a singleton this is necessary. Apart from this case(Singleton) I did not see people trying to synchronize static variables.Regards,Suresh Koya
-----Original Message-----
From: An interest list for Sun Java Center J2EE Pattern Catalog [mailto:J2EEPATTERNS-INTEREST@JAVA.SUN.COM]On Behalf Of Julia Liu
Sent: Friday, April 01, 2005 9:47 PM
To: J2EEPATTERNS-INTEREST@JAVA.SUN.COM
Subject: Re: Is Singleton thread safe?==================================================================== Companion Site: http://www.corej2eepatterns.com J2EE BluePrints: http://java.sun.com/blueprints/corej2eepatterns List Archive: http://archives.java.sun.com/archives/j2eepatterns-interest.html Unsubscribing: email "signoff J2EEPATTERNS-INTEREST" to listserv@java.sun.comThanks for reply. Could I Synchronized static varible?
Sureshbabu Koya <Sureshbabu.Koya@SYMPHONYSV.COM> wrote:Making a singleton thread safe is up to you. You should also think about how the performance get a hit if you want to make a singleton threadsafe.regards,Suresh==================================================================== Companion Site: http://www.corej2eepatterns.com J2EE BluePrints: http://java.sun.com/blueprints/corej2eepatterns List Archive: http://archives.java.sun.com/archives/j2eepatterns-interest.html Unsubscribing: email "signoff J2EEPATTERNS-INTEREST" to listserv@java.sun.com-----Original Message-----
From: An interest list for Sun Java Center J2EE Pattern Catalog [mailto:J2EEPATTERNS-INTEREST@JAVA.SUN.COM]On Behalf Of Julia Liu
Sent: Friday, April 01, 2005 9:24 PM
To: J2EEPATTERNS-INTEREST@JAVA.SUN.COM
Subject: Is Singleton thread safe?Hi,Is Singleton thread safe? Why?Thanks
Julia Liu
Yahoo! Messenger
Show us what our next emoticon should look like. Join the fun. ==================================================================== Companion Site: http://www.corej2eepatterns.com J2EE BluePrints: http://java.sun.com/blueprints/corej2eepatterns List Archive: http://archives.java.sun.com/archives/j2eepatterns-interest.html Unsubscribing: email "signoff J2EEPATTERNS-INTEREST" to listserv@java.sun.com
Julia Liu
Yahoo! Messenger
Show us what our next emoticon should look like. Join the fun. ==================================================================== Companion Site: http://www.corej2eepatterns.com J2EE BluePrints: http://java.sun.com/blueprints/corej2eepatterns List Archive: http://archives.java.sun.com/archives/j2eepatterns-interest.html Unsubscribing: email "signoff J2EEPATTERNS-INTEREST" to listserv@java.sun.com