Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » J2EE Pattern »

Re: Is Singleton thread safe?

Sureshbabu Koya

2005-04-01


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?

Thanks 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
-----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
==================================================================== 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
==================================================================== 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
©2008 junlu.com - Jax Systems, LLC, U.S.A.