cuốn sách gpt4 ai đã làm

java - Tomcat 中 Web 服务的 Shutdownhook

In lại Tác giả: Walker 123 更新时间:2023-11-28 22:12:49 25 4
mua khóa gpt4 Nike

我正在 Tomcat 中使用 Jax-ws 发布 Web 服务

@WebService()
public class ChatService
...followed by a constructor and several public methods

问题是我如何定义一个在 web 服务关闭时立即调用的方法。我需要它来停止一些线程并防止内存泄漏。

这是 web.xml 的一部分


com.sun.xml.ws.transport.http.servlet.WSServletContextListener


JAX-WS endpoint
WSServlet
WSServlet
com.sun.xml.ws.transport.http.servlet.WSServlet
1


WSServlet
/*

câu trả lời hay nhất

您需要定义自己的 ContextListener 并将其添加到 web.xml 的监听器标记中。实现 javax.servlet.ServletContextListener 并覆盖 contextDestroyed 方法。有关详细信息,请参阅本教程:http://www.mkyong.com/servlet/what-is-listener-servletcontextlistener-example/

public class CleanupContextListener implements ServletContextListener{

@Override
public void contextDestroyed(ServletContextEvent arg0) {
// TODO: Your cleanup code here
}

@Override
public void contextInitialized(ServletContextEvent arg0) {
// Intentionally Empty
}
}

关于java - Tomcat 中 Web 服务的 Shutdownhook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24856453/

25 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress