Hi, * Informations :* System : Ubuntu 10.04 Server
Tomcat : Using CATALINA_BASE: /usr/local/tomcat7 Using CATALINA_HOME: /usr/local/tomcat7 Using CATALINA_TMPDIR: /usr/local/tomcat7/temp Using JRE_HOME: /usr/lib/jvm/java-6-sun Using CLASSPATH: /usr/local/tomcat7/bin/ bootstrap.jar:/usr/local/tomcat7/bin/tomcat-juli.jar Server version: Apache Tomcat/7.0.12 Server built: Apr 1 2011 06:13:02 Server number: 7.0.12.0 OS Name: Linux OS Version: 2.6.32-24-server Architecture: amd64 JVM Version: 1.6.0_24-b07 JVM Vendor: Sun Microsystems Inc. Tomcat script : # Tomcat auto-start # # description: Auto-starts tomcat 7 # processname: tomcat7 # pidfile: /var/run/tomcat.pid export JAVA_HOME=/usr/lib/jvm/java-6-sun case $1 in start) sh /usr/local/tomcat7/bin/startup.sh ;; stop) sh /usr/local/tomcat7/bin/shutdown.sh ;; restart) sh /usr/local/tomcat7/bin/shutdown.sh sh /usr/local/tomcat7/bin/startup.sh ;; esac exit 0 *Problem 1:* I use Tomcat7 to host a socket server. My application use ServletContextListener to start as well as to stop ( contextInitialized and contextDestroyed ). Each time that my socket server receive a connection with : Socket java.net.ServerSocket.accept() I put the socket in a thread, and the thread manage the dialog with the client ( device, not a browser :p ) To manage a pool of thread, I use the class : ExecutorService In the thread there is a loop with a int java.io.Reader.read(char[] cbuf) My problem is when i want to stop tomcat with : sudo /etc/init.d/tomcat stop I received this event on my application by implementing the class ServletContextListener and using the function contextDestroyed : When contextDestroyed is called, I close all the socket and thread. But it takes time, and because of that, I always have : SEVERE: The web application [/SERVER] registered the JDBC driver [org.postgresql.Driver] but failed to unregister it when the web applicatio$ May 19, 2011 4:30:21 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads SEVERE: The web application [/SERVER] appears to have started a thread named [pool-3-thread-1] but has failed to stop it. This is very likel$ May 19, 2011 4:30:21 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads SEVERE: The web application [/SERVER] appears to have started a thread named [pool-3-thread-2] but has failed to stop it. This is very likel$ May 19, 2011 4:30:21 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads SEVERE: The web application [/SERVER] appears to have started a thread named [pool-2-thread-2] but has failed to stop it. This is very likel$ May 19, 2011 4:30:21 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads SEVERE: The web application [/SERVER] appears to have started a thread named [pool-3-thread-3] but has failed to stop it. This is very likel$ May 19, 2011 4:30:21 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads *Question 1 :* Is there a way to change the timeout of the stop function ? *Question 2 :* I also heard that sometime contextDestroyed and contextInitialized is called at unexpected time. Is it related to the use of memory ? By example, if there is a leaked memory, is it possible that tomcat decide to close all the application and restart it ? To summarize these questions : " When contextDestroyed is called ? " *Problem 2 :* After sudo /etc/init.d/tomcat stop , I try again to start the server, but i got : May 19, 2011 4:28:22 PM org.apache.catalina.core.AprLifecycleListener init INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.pa$ May 19, 2011 4:28:22 PM org.apache.coyote.AbstractProtocolHandler init INFO: Initializing ProtocolHandler ["http-bio-8080"] May 19, 2011 4:28:22 PM org.apache.coyote.AbstractProtocolHandler init SEVERE: Failed to initialize end point associated with ProtocolHandler ["http-bio-8080"] java.net.BindException: Address already in use <null>:8080 at org.apache.tomcat.util.net.JIoEndpoint.bind(JIoEndpoint.java:378) at org.apache.tomcat.util.net.AbstractEndpoint.init(AbstractEndpoint.java:482) at org.apache.coyote.AbstractProtocolHandler.init(AbstractProtocolHandler.java:354) at org.apache.coyote.http11.AbstractHttp11JsseProtocol.init(AbstractHttp11JsseProtocol.java:119) at org.apache.catalina.connector.Connector.initInternal(Connector.java:910) at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:101) at org.apache.catalina.core.StandardService.initInternal(StandardService.java:559) at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:101) at org.apache.catalina.core.StandardServer.initInternal(StandardServer.java:781) at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:101) at org.apache.catalina.startup.Catalina.load(Catalina.java:572) at org.apache.catalina.startup.Catalina.load(Catalina.java:595) 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.load(Bootstrap.java:262) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:430) Caused by: java.net.BindException: Address already in use at java.net.PlainSocketImpl.socketBind(Native Method) at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:383) at java.net.ServerSocket.bind(ServerSocket.java:328) at java.net.ServerSocket.<init>(ServerSocket.java:194) at java.net.ServerSocket.<init>(ServerSocket.java:150) at org.apache.tomcat.util.net.DefaultServerSocketFactory.createSocket(DefaultServerSocketFactory.java:48) at org.apache.tomcat.util.net.JIoEndpoint.bind(JIoEndpoint.java:365) I don't understand, because sockstat -p 8080 give an empty answer : USER PROCESS PID PROTO SOURCE ADDRESS FOREIGN ADDRESS STATE And if try to stop again tomcat i got : 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:456) 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:352) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433) *Question 3 : *is that normal ? Thx for the help !