You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-user@xml.apache.org by "Micael Ericsson (QIN)" <Mi...@ein.ericsson.se> on 2001/08/28 15:30:44 UTC

RE: How to share a variable of a service class among different cl ients' requests?

Design pattern Singelton solves this. Creating one unique instance that can be acces by several 'services'. This instance 'lives' from first acces until webserver/soap stops.

Creating this in Java is easy:
- make constructor private so that it is not accesible from outside
- make a static method for getting sole instance like:
>final public class GlobalSettings 
>{
>  private globalSettings() {}; 
>  public static GlobalSettings getInstance()
>  {
>	if (soleInstance == null)
>		soleInstance = new GlobalSettings ();
>	return soleInstance;
>  }
>  ...
>}
>private GlobalSettings soleInstance = null;

Then add get/set methods for parameters you want to share.

/Micael E.

-----Original Message-----
From: Wenbiao Han [mailto:wenbiao.han@ulticom.com]
Sent: Tuesday, August 28, 2001 3:11 PM
To: soap-user@xml.apache.org
Subject: How to share a variable of a service class among different
clients' requests?


 Hi:

 Suppose a member variable x of a Java service class X has a HashTable type,
I am wondering how the different clients can add or delete entries in the
variable x? Can I set the scope of the service class as "application" and
synchronize the adding/deleting mehods when the client
wants to add/delete the HashTable entries?

 As I understand, only one instance of a service class is created if
"application" scope is set. The question is whether the same variable
instance X.x can be accessed by different clients?

 Thanks in advance for your answers

Kelvin