• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

tomcat not stopping during first instance

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I am developing a Queue message proof of concept on Spring-MVC 5.x, Java 8 and Tomcat server 9.x. While reading the queue messages from the Oracle table, thread warning messages appending in the Catalina log file.

If I try to shutdown and start the tomcat server, the tomcat server is not shutting down during the first time but on the next call tomcat server is shutting down and a memory leak warning message is logged in the log file.

Please help why I am unable to shutdown the tomcat server during the first time.

Log details

INFO [main] org.apache.catalina.core.Aprlifecyclelistener.lifecycleEvent The Apache Tomcat Native library which allows using OpenSSL was not found on the java.library.path
INFO [main] org.apache.coyote.Abstract Protocol.init Initializing ProtocolHandler ["http-nio-9090"]
INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["https-jsse-nio-8443"]
INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 912 ms
INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet engine: [Apache Tomcat/9.0.53]
INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive [/apps/opt/tomcat/webapps/Books.war]
WARNING [localhost-startStop-1] org.apache.tomcat.util.descriptor.web.WebXml.setVersion Unknown version string [4.0]. Default version will be used.
INFO [localhost-startStop-1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup: time and JSP compilation time.
INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [/apps/opt/tomcat/webapps/Books.war] has finished in [62,365] ms
INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-9090"]
INFO [main] org.apache.coyote.AbstractProtocol.start Starting Protocollandler ["https-jsse-nio-8443"]
INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 82019 ms
INFO [main] org.apache.catalina.core.StandardServer.await A valid shutdown command was received via the shutdown port. Stopping the Server instance.

INFO [main] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ["http-nio-9090"]
INFO [main] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ["https-jsse-nio-8443"]
INFO [main] org.apache.catalina.core.StandardService.stopInternal Stopping service [Catalina]
WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferences Threads The web application [Books] appears to have started a thread named [AQThread] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread: java.lang.Thread.sleep(Native Method)

WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferences Threads The web application [Books] appears to have started a thread named [AQThread] but has failed to stop it. This is very likely to create a nemory leak. Stack trace of thread:
java.net.SocketInputStream.socketRead0(Native Method)
java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
java.net.SocketInputStream.read(SocketInputStream.java:171)
java.net.SocketInputStream.read(SocketInputStream.java:141)
oracle.net.ns.Packet.receive(Packet.java:282)
oracle.net.ns.DataPacket.receive(DataPacket.java:103)
oracle.net.ns.NetInputStream.getNextPacket(NetInputStream.java:230)
oracle.net.ns.NetInputStream.read(NetInputStream.java:175)
oracle.net.ns.NetInputStream.read(NetInputStream.java:100)
oracle.net.ns.NetInputStream.read(NetInputStream.java:85)
oracle.jdbc.driver.T4CSocketInputStreamWrapper.readNextPacket(T4CSocketInputStreamwWrapper.java:122)
oracle.jdbc.driver.T4CSocketInputStreamwrapper.read(T4CSocketInputStreamWrapper.java:78)
oracle.jdbc.driver.T4CMAREngine.unmarshalUB1(T4CMAREngine.java:1179)
oracle.jdbc.driver.T4CMAREngine.unmarsha1SB1(T4CMAREngine.java:1155)
oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:279)
oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:186)
oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:521)
oracle.jdbc.driver.T4CCallableStatement.doOall8(T4CCallableStatement.java:202)
oracle.jdbc.driver.T4CCallableStatement.executeForRows(T4CCallableStatement.java:1005)
oracle.jdbc.driver.OracleStatement.doExecutewithTimeout(OracleStatement.java:1307)
oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3449)
oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3493)
oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:1491)
oracle.AQ.AQOracleQueue.dequeue(AQOracleQueue.java:1625)
oracle.AQ.AQOracleQueue.dequeue(AQOracleQueue.java:1326)

INFO [AQThread] org.apache.catalina.loader WebappClassLoaderBase.checkStateForResourceLoading Illegal access: this web application instance has been stopped already. Could not load [oracle.AQ.AQOracleQueue]. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.

java.lang.IllegalStateException: Illegal access: this web application instance has been stopped already. Could not load [oracle.AQ.AQOracleQueue]. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading(WebappClassLoaderBase.java:1435)
at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForClassLoading(WebappClassLoaderBase.java:1423)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1262)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1223)
 
Saloon Keeper
Posts: 24501
167
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tomcat is a Java Application and like all Java Applications, the JVM that Tomcat runs in cannot shut down until all Threads generated by the Application have shut down. So it is absolutely essential that all Threads spawned by webapps must be terminated or Tomcat will hang.

Please note that it is absolutely forbidden to spawn a Thread in a Tomcat webapp servlet or in an Enterprise JavaBean, per the JEE specifications. Tomcat cannot enforce this, but if you do, you risk randomly corrupting any and every webapp running in that instance of Tomcat and possibly crashing Tomcat itself. And by "random" I mean you may get lucky and it "works" for 20 years, but Murphy's Law says that when it finally doesn't work, the time and manner that the failure occurs will be extremely inconvenient. Not to mention that debugging Threading errors is about 10 times harder than it is for single-thread code and you don't want to have to do that while management is pressing for a quick fix to a major outage.

The recommended place for a webapp to spawn Threads in in a ServletContextListener. You can spawn Threads in the startup method and shut them down in the shutdown method. Threads that were spawned from those threads are OK also, as long as you clean everything up properly. Just don't spawn a Thread in a servlet's process(), doGet() doPost() or other request-processing method!.
 
Sheriff
Posts: 22504
122
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In JEE, you shouldn't spawn threads at all, but instead use ManagedExecutorService or ManagedScheduledExecutorService. Another option is to use @Asynchronous. All three options will make use of the container's thread pool(s).

Note that this does not apply to Tomcat. For that, Tim suggestion still holds.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic