users@glassfish.java.net

[gf-users] Re: Creating and using long lasting threads

From: Chris Folsom <jcfolsom_at_pureperfect.com>
Date: Mon, 29 Dec 2014 02:28:28 -0700

Threads aren't synchronized. Critical sections (i.e. Objects) are synchronized.

http://en.wikipedia.org/wiki/Semaphore_%28programming%29

JEE servers are meant to be managed environments and spawning your own threads is HIGHLY discouraged for several reasons. I'd suggest using a different approach, such as Quartz, Timer or this:

http://stackoverflow.com/questions/13932083/jboss-java-ee-container-and-an-executorservice

Does your thread really need to be running all the time? Is it constantly performing work? My guess is probably not and you'd be better off with a scheduled process. Newer Java apps (since 1.5/2004) should typically not be calling Thread directly and should not contain any references to java.lang.Thread anywhere in the code base. If you're code contains references to java.lang.Thread, there's a 99.9999% chance that you're doing it wrong.


-------- Original Message --------
Subject: [gf-users] Creating and using long lasting threads
From: Mladen_Adamović <mladen.adamovic@gmail.com>
Date: Mon, December 29, 2014 2:54 am
To: users@glassfish.java.net

Hi,

Our webapp creates several background long lasting threads (almost permanent).
Those threads are worker threads which are synchronized and designed for performance, no dead locks and fastest user experience.

However, it seems that Glassfish doesn't love long lasting threads when a Servlet opens a thread with new Thread(something).start() glassfish admin console might  hand with "long lasting thread detected....".

Any way to suggest to Glassfish that those threads are app based background threads?
Maybe setting then to "Deamon" would do, but those deamon threads might prevent JM to shutdown.