简体   繁体   English

有没有一种方法可以通过编程方式使Tomcat停止监听http端口

[英]Is there a way to programmatically pause Tomcat from listening to http port

When a Tomcat application server starts, i need to make sure all other interfacing device is online before listening to the incoming HTTP request. 当Tomcat应用程序服务器启动时,我需要确保所有其他接口设备都处于联机状态,然后再侦听传入的HTTP请求。 Is there a way to do so programatically from java? 有没有办法从Java编程地做到这一点?

One way to do this would be to set the size of the thread pool associated with the http connector to zero (minSpareThreads) and then use JMX to set it to a higher value. 一种方法是将与http连接器关联的线程池的大小设置为零(minSpareThreads),然后使用JMX将其设置为更大的值。

Just a theory - not sure if it will work. 只是一个理论-不确定是否会起作用。

Another option would be to explore extending the connectors with an ability to start / stop via JMX. 另一个选择是探索扩展连接器并使其能够通过JMX启动/停止的能力。

This post also outlines how to stop / start a connector using JMX. 这篇文章还概述了如何使用JMX停止/启动连接器。 http://java-monitor.com/forum/showthread.php?t=169 http://java-monitor.com/forum/showthread.php?t=169

If the wait is short, then I would try using a Filter. 如果等待时间很短,那么我将尝试使用过滤器。 See 看到
http://www.oracle.com/technetwork/java/filters-137243.html http://www.oracle.com/technetwork/java/filters-137243.html
http://docs.oracle.com/javaee/5/tutorial/doc/bnagb.html http://docs.oracle.com/javaee/5/tutorial/doc/bnagb.html
You can check your interfacing devices in it's init method. 您可以使用init方法检查接口设备。 You do't need to do anything in it's doFilter method. 您不需要在它的doFilter方法中做任何事情。

public class TestFilter implements Filter {
  public void init(FilterConfig config) throws ServletException{
                     System.out.println("init of TestFilter");
                     // Make sure all other interfacing device is online here.
  }
  public void destroy(){}        
  public void doFilter(ServletRequest req,ServletResponse resp,FilterChain chain)
     throws ServletException, IOException {   
                     chain.doFilter(req,resp);
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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