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

E

eftal

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.
 
I

Ian Mills

eftal said:
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.
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.
 
D

Daniel Dyer

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.
 
E

eftal

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.
 
E

eftal

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.
 
D

Daniel Dyer

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.

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.
 
T

Thomas Hawtin

eftal said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top