You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-user@ws.apache.org by "federico.fiorillo@inwind.it" <fe...@inwind.it> on 2001/08/28 15:45:05 UTC

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

but a request to a web server is statless. 
the only think that you can do is: do a request and listen a response. different thinks are out of 'normal' implementation. the concept of static variable are a forced work that a web server can do and onother web server cannot. i think you need to find others solution at you software. again, consider tha case where you have a balancing between some machine. who of these have you static variable?

federico

ps: sorry for my english.

>>>>>>

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