在我的代码中停止\启动连接器 [英] stop\start connector within my code

查看:45
本文介绍了在我的代码中停止\启动连接器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要停止然后以编程方式启动 https 连接器.在 tomcat 6 中,以下代码片段工作正常:

I need to stop and then start the https connector programmatically. In tomcat 6 the following scrap of code works fine:

        final ObjectName objectNameQuery = new ObjectName("*:type=Connector,port=443,*"); 
        MBeanServer      mbeanServer = null;
        ObjectName       objectName  = null;

        for (final MBeanServer server : (List<MBeanServer>) MBeanServerFactory.findMBeanServer(null))
        {
            if (server.queryNames(objectNameQuery, null).size() > 0)
            {
                mbeanServer     = server;
                objectName      = (ObjectName) server.queryNames(objectNameQuery, null).toArray()[0];

                break;
            }
        }

        // now we restart the connector that we just found. We sleep a little, but I am
        // not actually sure 1) how long we should sleep for or 2) if sleeping is
        // necessary at all.
        if (mbeanServer != null)
        {
            mbeanServer.invoke(objectName, "stop", null, null);                

            Thread.sleep(waitForStopInSec * 1000);

            mbeanServer.invoke(objectName, "start", null, null);

            log.warn("https Connector was restarted");
        }

但是在 tomcat 7 (7.0.23) 中,连接器并没有停止!所以我使用这行代码调用了 destroy() 方法(在调用 stop() 方法之后):mbeanServer.invoke(objectName, "destroy", null, null);

But in tomcat 7 (7.0.23) the connector does not stopped! So I invoked the destroy() method (right after invoking the stop() method) using this line of code: mbeanServer.invoke(objectName, "destroy", null, null);

在这种情况下,连接器确实停止了.但是当我尝试启动它时,连接器没有启动,我得到了这个异常:

In this case the connector indeed stopped. But when I tried to start it, the connector did not start and I got this exception:

28/03/12 18:32:01 ERROR T:CommServerScheduler_Worker-1 TrustStoreRefreshJob.refreshHTTPSConnectors - failed to restart connector 
javax.management.InstanceNotFoundException:    Catalina:type=Connector,port=443,address="/192.168.201.24"
     at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getMBean(DefaultMBeanServerInterceptor.java:1094)
     at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:833)
     at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:761)
     at tool.security.TrustStoreRefreshJob.refreshHTTPSConnectors(TrustStoreRefreshJob.java:79)
     at tool.security.TrustStoreRefreshJob.executeJob(TrustStoreRefreshJob.java:32)
     at com.nextnine.common.scheduler.AbstractJobLogic.execute(AbstractJobLogic.java:47)
     at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
     at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:525)

关于如何在 tomcat 7 中停止然后启动连接器的任何想法?最好以优雅的方式.提前致谢,家伙

Any ideas of how I can stop and then start the connector in tomcat 7? Preferable in a graceful manner. Thanks in advance, Guy

推荐答案

这取决于您如何定义停止".默认情况下,Tomcat 在 init() 期间绑定到端口并在 destroy() 期间解除绑定.在默认情况下,stop() 只是停止处理新连接,但它可能不会停止这些连接的建立(取决于 - 除其他外 - 底层操作系统).

It depends on how you are defining "stop". By default, Tomcat binds to the port during init() and unbinds during destroy(). In the default case stop() just stops processing new connections but it may not stop those connections being made (depending on - amongst other things - the underlying OS).

如果在 server.xml 中为连接器设置 bindOnInit="false",您可能会得到更好的结果.使用此设置,端口将在 start() 被调用时绑定,在 stop() 被调用时未绑定.

You may get better results if you set bindOnInit="false" for the connector in your server.xml. With this setting the port will be bound when start() is called an unbound when stop() is called.

这篇关于在我的代码中停止\启动连接器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆