• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

Tomcat shutdown ERRORs due to ThreadLocals  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any idea how to prevent the following logged ERROR on shutdown of Tomcat (i.e. what cleanup do I need to do on my shutdown of my application that uses Websockets):

[2018-11-15 18:33:20,353] [localhost-startStop-2] ERROR (org.apache.catalina.loader.WebappClassLoaderBase)  The web application [myapp] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@bb5f817]) and a value of type [org.glassfish.grizzly.ThreadCache.ObjectCache] (value [org.glassfish.grizzly.ThreadCache$ObjectCache@3d25e85f]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
 
Bartender
Posts: 20562
120
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm going to have to assume that you're doing that weird thing where a webapp uses Glassfish resources even though the webapp server itself is Tomcat.

It sounds like you are spawning threads in your webapp. The J2EE standard expressly forbids that in any code that's being executed in response to a servlet request - and that includes servlet code itself. Servlets run under threads that are pulled from a pool, used just long enough to service the request, then returned to the pool. If you spawn a subthread of that thread, you end up polluting the thread pool, which can randomly crash Tomcat.

In the event that you spawn a thread(s) in ServletContextListener - which, unlike servlets, is allowed to spawn child threads, you are obligated to terminate those threads in a corresponding shutdown ServletContextListener method. Failing to do so will annoy Tomcat and delay its termination, since a JVM cannot exit to the OS until all of its threads have terminated.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!