views:

233

answers:

1

My system has 3-4 web services which communicate with each other via UDP, so on start each Web Service needs to start a UDP listener thread, can this be done in the constructor of the Web Service itself?

I've done some reading (not sure if it is correct) and noticed that sometimes people refer to Web Services as "stateless" and mention that everytime a client connects it will create a new web service and thus run the constructor - but I want to run my constructor only a single time (when the service is deployed) and have it start my UDP listener only once ... and keep it listening even when no clients are connected...

Does that make any sense? How do people usually resolve this type of situation?

Any advice would be much appreciated. Thanks,

A: 

You can use static initialization:


static {
  Listener.initialize();
}
Bozho
Within the @WebService class itself?But does this really mean that each time a client executes a method the default constructor is called again?
Shaitan00
I guess in depends on the implementation - it is not unlikely that some pool is used. But better don't use default constructor in managed environment :)
Bozho