This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
The moose likes Java in General and the fly likes My Program Sometimes Would Not Wake Up Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "My Program Sometimes Would Not Wake Up" Watch "My Program Sometimes Would Not Wake Up" New topic

My Program Sometimes Would Not Wake Up

Andrew Kwong
Ranch Hand

Joined: Dec 11, 2001
Posts: 40
I have a small java program running on a NT server. This program spawns a thread that wakes up every 2 minutes to monitor a log file. It usually runs okay for hours and then, all of a sudden, it would go to sleep and never wake up.
There are very little activities on the server and I am using the method "sleep(2*60*1000);" to put the thread to sleep for 2 minutes.
Any idea why?

Karthikraj Magapu

Joined: Dec 04, 2001
Posts: 9
does the program actually go to sleep and never wake up or does it crash ?
maybe something you are doing in the code is throwing an exception that is not being handled ?
Since the program works fine for a few hours, it may be somthing related to memory ?
Can you post the code of the loop ?
What does the program do when it wakes up ? maybe the file handling of the log file causes some exception after sometime ?
Just shooting off some thoughts ...
hope this helps ..

[This message has been edited by Karthikraj Magapu (edited December 12, 2001).]

Andrew Kwong
Ranch Hand

Joined: Dec 11, 2001
Posts: 40
This is what my program does:
It spawns a new thread when the program starts.
This thread wakes up once every 2 minutes to check the log file.
It searches for a specific string at the end of the file.
If the string is not found, it goes back to sleep.
If the string is found, it kills the data load job, updates an Oracle table, restarts the data load job and goes back to sleep.
I don't believe the program has crashed. I think I have captured most, if not all, of the exceptions.
It seems to me that this has something to do with high CPU usage on the NT server. Last time this happened, I noticed that the CPU usage was close to 100% for a long time. Is it possible that NT has swapped my job out and never swaps it back in? If so, how can I prevent this from happening?
I agree. Here's the link:
subject: My Program Sometimes Would Not Wake Up