This might start a debate on Java coding style, but I'll take the risk...
I assume that there is a new serviceContext on each request? If not, then you
can just check to see if you've already put the map there.
If not, you could create a static Map and do something like this:
private static Map map = null;
public void init(ServiceContext serviceContext) {
if ( map == null ) {
synchronized( this ) {
map = initializeMyMap();
}
}
// put the map into the serviceContext
}
It will work, but many would argue that you should never use static variables.
cheers,
Michael Davis
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Tuesday, June 12, 2007 1:35 PM
To: [email protected]
Subject: [Axis2] - How to get information at startup of tomcat
Hi all,
I developed a webservice with axis/tomcat, which got some information from a
database.
All worked fine, but the problem is that the information was not modified
frequently, and was obtained each time that my webservice was invoked.
So, I decided to migrate my webservice to axis2, ant put inside my service
class the following methods:
public void init(ServiceContext serviceContext) {
// my initialization code here
}
public void destroy(ServiceContext serviceContext) {
// this code will be executed when the service is unloaded
}
In the method init I do a query to a database to get the information, and put
it in a Map of the ServiceContext.
At this point all works like I want, the method init is invoked only one time.
The problem is that I modified the scope from "application" to "request", to
force the creation of a new instance of the service class per request. I did
this modification because I want to process various requests in simultaneous.
With this modification, each time a request is done the init method is invoked,
and I want that it will be only invoked one time.
How can I solve this problem?
Regards,
Rui Torres
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]