• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

all threads die when after 2 hours when cpu reaches 100%

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have application to run threads and each thread connecting to diffrent database and make some process in a schadual task .

the problem is all the theads hangs when the cpu is 100 % utilies and this happend not imedatly but just after certine time like 3 -4 hours or may be 10 hours
and this is my run method
public void run() {



while(true){
try{
Thread thread = Thread.currentThread();


synchronized(thread)
{

Process();
this.sleep(this.period);
}catch(Exception eee){
eee.printStackTrace();
return;
}

}
}



 
ayman elgharabawy
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No Body has a advice for my problem

i will explain again i have multi threading applicatin and i have to put it in a very loaded server and this server some times the cpu reaches 100%usages and this makes my program stop all threads and die
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by ayman elgharabawy:
No Body has a advice for my problem



I understand your frustration, but we here at the JavaRanch are volunteers, so questions get answered when someone gets around to it. You really aren't giving us much to go on, so everyone moves on to the questions that are better documented and easier to answer.
Looking at the code you gave us, it is clear that you don't understand multithreading well (you don't need a "synchronized" block in your run() method because there should only be one thread in that method). Check out the
Java Tutorial: Threads chapter for the basics.
It sounds like you are trying to write a scheduler. Why reinvent the wheel when the API has two: javax.swing.Timer java.util.Timer
Look at them and see if they can get you closer to your goal.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See if I'm getting the problem ...

You have some number of threads that you start at server startup.

Each thread monitors one database. It processes any outstanding work it finds in the database, then sleeps, then repeats.

CPU usage grows over time, finally hits 100% and things stop working.

Does memory usage grow, too?

Sounds like something is running away and never stopping. Do you start new threads over time? Do you get floods of new tasks on the database at some point?

Any chance you're on JDK 5? There's a neat Consolethat lets you monitor threads and memory and such remotely.
 
ayman elgharabawy
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok guys, the cpu usage is 100% but the memory usage is not
and i tried java.util.Timer and timerTask and i got the same results
if any body wants me to send him the code or try my program i have no problem
i want to know how to make the schadual task robust enough even if the server is too loaded or guarantee the thread never dies

here is part of my code after some summary


public class easythread extends Thread{

public static void main(String [] args)
{
for(int i=0;i<5;i++){
easythread et= new easythread ();
}

public void run() {
while(true){
Process();
this.sleep(this.period);

}

}

}
 
ayman elgharabawy
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have also to mention that the program doesnt use much cpu time
plus he cpu doesnt increase but i have already loaded cpu even befor my program run!!!
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by ayman elgharabawy:

i want to know how to make the schadual task robust enough even if the server is too loaded or guarantee the thread never dies



Can't be done. If you write bogus enough code you can crash the most hardened system. If your system is already at 100% CPU use, I'd say that may be your problem right there. Upgrade your hardware to something that can take the load.
As for the code you've shown us, you are still not telling us much. You may be doing something in the Process() method, like not closing database connections, which is causing your problem, but we'd never know. Do you get any exceptions?
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Some systems will have accounting limits and will automatically kill a process that exceeds those limits. If you're on a UNIX platform, try running "ulimit" to see if there's a CPU usage limit.
 
ayman elgharabawy
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have no exception at all and i close the database connection and all the resultsets and statements

i think it is a java thread problem as i have vb programs doing the same tasks
and works fine even if the cpu is 100% usage
my server is win2000 and i couldnt change to linux

even if any body try to make any simple thread program and put it in this case
he will get the same result on windows..
and this is not robust at all!!!
 
reply
    Bookmark Topic Watch Topic
  • New Topic