Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2006

Tip: Looking for answers? Try searching our database.

Strange problem with a thread that goes to sleep....

Thread view: 
eftal - 25 Jan 2006 20:07 GMT
Hello,

I have a JAva program that runs all day long mimicking daemons.  IT
calls Thread.sleep between each iteration.  I am running it on an NT
server.

Eerything is wrapped in try / catch block...however the program will
sometimes quit.  It will not throw an exception, or give any kind of
JVM error.  Its as if somerthing wiped it out of memory.  Here are the
exact 3 lines of code:

log("sleeping");
Thread.sleep(30000);
log("woke up");

I was thinking that it somehow did not wake up, but I see no trace of
java.exe in the task manager when it quits.  I found out through my
research that a java process might sleep and never wake up if the
system time is adjusted during its sleep.  However, I don't belieeve
this is happening b/c I don't have a dead java.exe process in the task
manager.

Another hint I recieved was that if someone logs onto the server, and
than logs off, it may send the java.exe a signal to shutdown...which
can be avoided with -XRS command line option.  However, I can not
recreate this scenario...

Anyone know what might be going on?

Thanks,
eF.
Ian Mills - 25 Jan 2006 20:23 GMT
> Hello,
>
[quoted text clipped - 27 lines]
> Thanks,
> eF.

It may be worth redirecting stdout and stderr to a file as sometimes
errors will be shown here that are not caught in your try/catch blocks.
Daniel Dyer - 25 Jan 2006 20:23 GMT
> Hello,
>
> I have a JAva program that runs all day long mimicking daemons.  IT
> calls Thread.sleep between each iteration.  I am running it on an NT
> server.

Are all your threads daemon threads?  The JVM will exit when there are  
only daemon threads remaining.

How long does the program run for before it dies?

> Eerything is wrapped in try / catch block...however the program will
> sometimes quit.  It will not throw an exception, or give any kind of
> JVM error.  Its as if somerthing wiped it out of memory.  Here are the
> exact 3 lines of code:

What are you catching?  Just Exception, or Throwable?  If you are using  
Java 5 you may also want to look into  
Thread.setDefaultUncaughtExceptionHandler, just to make sure.

> log("sleeping");
> Thread.sleep(30000);
> log("woke up");

> I was thinking that it somehow did not wake up, but I see no trace of
> java.exe in the task manager when it quits.  I found out through my
> research that a java process might sleep and never wake up if the
> system time is adjusted during its sleep.  However, I don't belieeve
> this is happening b/c I don't have a dead java.exe process in the task
> manager.

It could be the JVM has crashed due to some bug or some misbehaving JNI  
code.

Signature

Daniel Dyer
http://www.dandyer.co.uk

eftal - 25 Jan 2006 21:01 GMT
Thanks a lot for the response.  Actually, the program is not
multithreaded...it is not using Daemon threads...within the main
program there is a while loop that runs forever unless there is a break
in the condition...it is within here that it sleeps and wakes up.
eftal - 25 Jan 2006 21:06 GMT
thanks for your response...yes, I think its JVM...but it seems
arbitrary.

1 - Program is not multithreaded....so its just a main with a while
loop that sleeps / wakes up in the lines I posted.  The last log entry
is "sleeping" from the main...it disappears after that.  So, no, its
not a daemon thread.

2 - It seems to go down at arbitrary times...sometimes it will run all
day without any issues.  Sometimes it'll crash 3-4 hours into operation.
Daniel Dyer - 25 Jan 2006 21:15 GMT
> thanks for your response...yes, I think its JVM...but it seems
> arbitrary.
[quoted text clipped - 6 lines]
> 2 - It seems to go down at arbitrary times...sometimes it will run all
> day without any issues.  Sometimes it'll crash 3-4 hours into operation.

Which exact version of the JVM are you using (run java -version)?

Are you using JNI or running any native processes via Runtime.exec()?

Are there any calls to System.exit() anywhere in your code?

What are you doing with the InterruptedException that Thread.sleep can  
throw?

Also, Ian's suggestion of redirecting standard error is a good one, it may  
reveal some more information.

Dan.

Signature

Daniel Dyer
http://www.dandyer.co.uk

Thomas Hawtin - 25 Jan 2006 22:29 GMT
> I have a JAva program that runs all day long mimicking daemons.  IT
> calls Thread.sleep between each iteration.  I am running it on an NT
> server.

Is NT still supported?

> Another hint I recieved was that if someone logs onto the server, and
> than logs off, it may send the java.exe a signal to shutdown...which
> can be avoided with -XRS command line option.  However, I can not
> recreate this scenario...

Sounds like they were referring to this bug (fixed way back in 1.3.0_04)

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4323062

Tom Hawtin
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.