简体   繁体   中英

How to start a listener from a Web Service? [Java Netbeans 6.7.1 & Tomcat 6.0.18]

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,

You can use static initialization:


static {
  Listener.initialize();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM