This week's book giveaway is in the XML and Related Technologies forum.
We're giving away four copies of Java XML & JSON and have Jeff Friesen on-line!
See this thread for details.
Win a copy of Java XML & JSON this week in the XML and Related Technologies forum!
  • 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 ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Tomcat shutdown ERRORs due to ThreadLocals  RSS feed

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.
Posts: 20307
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.
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!