简体   繁体   中英

Apache Tomcat Shutdown :java.net.ConnectException: Connection refused

I installed tomcat 7 on centos 5.8. Then I executed ./startup.sh and ./shutdown.sh, it worked well.

Then I put a something.war under the webapps/. it worked well too. But when i shutdown the tomcat, it doesn't work and throws an exception:

java.net.ConnectException: Connection refused
    at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
        at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
        at java.net.Socket.connect(Socket.java:529)
        at java.net.Socket.connect(Socket.java:478)
        at java.net.Socket.<init>(Socket.java:375)
        at java.net.Socket.<init>(Socket.java:189)
        at org.apache.catalina.startup.Catalina.stopServer(Catalina.java:499)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.catalina.startup.Bootstrap.stopServer(Bootstrap.java:371)
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:453)

And i'm sure:

  1. The tomcat is running and works well before i execute ./shutdown.sh

  2. The process of the tomcat is still alive, but it isn't listening the port 8080, after i execute ./shutdown.sh

Some possibilities come to my mind:

  • It is possible that your webapp starts a thread that doesn't run as "daemon" - thus keeping the process alive. Change this in the webapp to behave more friendly - or implement a listener that shuts down the thread when your webapp is shutting down. You can test this by triggering a thread dump ( kill -3 pid ) on the running tomcat process, the output will (most likely) end up in catalina.out
  • There might be another tomcat running, on a different port - that's what you see in ps output
  • You have changed the "shutdown" port (see tomcat's server.xml ) - that's what shutdown.sh is contacting in order to instruct tomcat to shut down

Check that you have localhost in /etc/hosts for 127.0.0.1

Mine used to be like this

127.0.0.1   centosIGW localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

It works after I add localhost to 127.0.0.1

127.0.0.1   centosIGW localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

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