Have your service endpoint interface implement javax.xml.rpc.server.ServiceLifecycle and implement the init() method. While there is no guarantee, the init() function is usually only called once the first request against the service endpoint interface is received.
Originally posted by alain martin: I have tried it, and init method runs after constructor, and anyway it is runned every call to webservice, not only with the first user.
This is just a reflection of the fact that Axis chooses to create a new Web service instance for each request. So in fact each Web Service instance only has one user, who is the first user of that instance.
Seems that in your case you need to manage something outside of the web service instances that Axis manages for you. In the init() method the container hands you an Object that you can cast to a javax.xml.rpc.server.ServletEndpointContext. From that you can use getServletContext() to get the interface to the web container javax.servlet.ServletContext. In the ServletContext you can use getAttribute() and setAttribute() to manage some application-wide name-value pairs. Using attributes a web service instance can find out if it is the first to instance to run and run some initialization code if necessary and store the resulting objects in the attributes while following instances can just grab these objects.
However you have to be careful as these application-wide attributes will be shared between all running web service instances. So you have to be sure to synchronize access to ServletContext and any attributes that are stored there (unless all instances are just reading from it; if somebody regularly performs read-write operation on the object then everybody has to synchronize access to the object):
Note that using lots of read-write operations on application-wide attributes will create a performance bottleneck.
Alternately you could try using class static variables in your web service class instead of attributes � but you should still wait until the init() method to initialize the shared objects, you still have to synchronize access to the shared objects, and the shared objects can still become a performance bottleneck.