variables 2005-10-10 - By Tim Wood
Back At 07:09 AM 10/10/05, SUBSCRIBE EJB-INTEREST anonymous wrote: >Hi, >Is there any advantage of having private,static member variable >(Initialized in the constructor of the class) in a non-singleton class. >Is so, please let me know.
To answer this, think about what that decl means: The class needs a single copy of the variable to use as an implementation detail. Preferably, the variable is fina, and, if it's a reference type, the object it points to is immutable. Then no synchro. issues. For clean initialization, set it up in a static block ; this is a good thread-safe way to build singletons too (R. Johnson).
If the object is mutable, say some master state table for all the instances, then you synchronize it. Since it is private & static, you don't put the synchronization in the method signatures, but synchronize explicitly on the object itself inside the class.
HTH, TW
=========================================================================== To unsubscribe, send email to listserv@(protected) and include in the body of the message "signoff J2EE-INTEREST". For general help, send email to listserv@(protected) and include in the body of the message "help".
|
|