Home arrow static arrow Java Programming [Archive] - Threads not Stopping on Linux
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Threads not Stopping on Linux
This topic has 9 replies on 1 page.

Posts:259
Registered: 4/27/00
Threads not Stopping on Linux  
Jul 25, 2002 5:38 AM



 
I am having a problem with Sun's JDK 1.4 on Linux. I am posting this because I wanted to see if anyone else has had this problem and what comments people might have.

I have a command-line program that pre-processes a bunch of data before it is loaded into a database. The program starts about 18 threads to accomplish its task: 1 management thread, and 17 data conversion threads (this seems to perform well on my platform). The problem is that sometimes, the threads do not terminate when the program terminates. I've done a ps -ef much later and found the thread processes still hanging around.

Anyone else seen this or shall I report a bug?

Platform: RedHat Linux 7.3 Kernel 2.4.18-3 SMP
Java -version output:

java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)

Thanks in advance.
 

Posts:403
Registered: 9/4/03
Re: Threads not Stopping on Linux  
Dec 30, 2003 2:16 PM (reply 1 of 9)



 
Yes, I am seeing this as well. My threads won't always die on a system.exit() on Linux.
 

Posts:1,657
Registered: 1/8/98
Re: Threads not Stopping on Linux  
Dec 30, 2003 7:41 PM (reply 2 of 9)



 
You need to make your threads "daemon" threads - see java.lang.Thread
 

Posts:27,518
Registered: 11/3/97
Re: Threads not Stopping on Linux  
Dec 30, 2003 9:56 PM (reply 3 of 9)



 
You need to make your threads "daemon" threads - see
java.lang.Thread

System.exit() terminates all threads, it doesn't matter what kind they are.
 

Posts:27,518
Registered: 11/3/97
Re: Threads not Stopping on Linux  
Dec 30, 2003 9:56 PM (reply 4 of 9)



 
Yes, I am seeing this as well. My threads won't
always die on a system.exit() on Linux.

And how did you determine this?
 

Posts:403
Registered: 9/4/03
Re: Threads not Stopping on Linux  
Jan 21, 2004 11:09 AM (reply 5 of 9)



 
Sorry for the late reply. I was on vacation. I determined this because I have a system.exit() call in my code and it does not terminate the JVM or any of the java threads. My program uses about 15 threads and after the system.exit call, they are all still running.

I know it is a Linux issue, because this exact same code works perfectly fine on Solaris, AIX, HPUX and NT.
 

Posts:727
Registered: 6/23/98
Re: Threads not Stopping on Linux  
Jan 21, 2004 1:54 PM (reply 6 of 9)



 
Sorry for the late reply. I was on vacation. I
determined this because I have a system.exit() call in
my code and it does not terminate the JVM or any of
the java threads.

Obviously your System.exit() didn't actually finish executing, and your original thread is still alive.

How do you know your exit() actually executed?
 

Posts:403
Registered: 9/4/03
Re: Threads not Stopping on Linux  
Jan 26, 2004 4:57 PM (reply 7 of 9)



 
Well like I said before, this exact same code works and the system.exit() is in fact being called on Solaris, NT, AIX and HPUX. There is no reason the logic in the code would flow any differently on Linux.
 

Posts:403
Registered: 9/4/03
Re: Threads not Stopping on Linux  
Jan 26, 2004 5:05 PM (reply 8 of 9)



 
My code calls a system.exit() on startup if the listen port it is trying to bind to is not available. Just to verify that the system.exit() call is being made, I printed some text to standard out just prior to the call, and then again after the call. I get nothing after the call. Which means the main thread is actually calling system.exit(). It's just not shutting down the JVM.
 

Posts:21
Registered: 02-12-13
Re: Threads not Stopping on Linux  
Jul 30, 2004 6:30 AM (reply 9 of 9)



 
Did you ever figure this problem out?
Did you try kill -3 on your PID to see the stack trace?

I am having issues with Linux as well, may or may not be related. If my system is using more memory than physical memory, i.e. doing a lot of swapping, sooner or later most of my Java threads get locked up "waiting on condition" in system/JRE level calls to things like Logger or like this:

"UDP Receiver Thread" prio=1 tid=0x0826f168 nid=0x223c waiting on condition [4e8d7000..4e8d7f18]
at java.io.UnixFileSystem.getBooleanAttributes(Unknown Source)
at java.io.File.exists(Unknown Source)
 
This topic has 9 replies on 1 page.