-
1. Re: Thread.sleep in mbean give 100% cpu
sfisque Apr 18, 2012 2:12 PM (in response to chitech)i guess the first question is, why are you spawning a thread inside of an EE container? you really should be using a Timer.
-
2. Re: Thread.sleep in mbean give 100% cpu
chitech Apr 18, 2012 4:19 PM (in response to sfisque)As I write in the first place. I am not creating any new threads. I just sleeping on the current thread that is executing the mbean. I have also tried to create only one new thread but with same result.
Maybe I can use the Timer class.
my flow for the mbean:
1. check db is running.
2. if not wait 5 min. Then repeat point 1
3. if db running. make a select
4. if select = false -> shutdown
5. if select = true -> continue with the rest
How can I use the Timer to do some task and make the main thread waiting? Must not do anything when the db is down
Something like this:
boolean dbRunning = false;
Timer timer = new Timer();
timer.schedule(new MyTask(), 300000);
while(!dbRunning); // Wait until the db is up running
timer.cancel();
...
...
class MyTask extends TimerTask {
public void Run() {
if (db == running) {
dbRunning = true;
}
}
}
-
3. Re: Thread.sleep in mbean give 100% cpu
sfisque Apr 18, 2012 10:22 PM (in response to chitech)yeah, the entire Thread api is a no-no in a EE contained environment.
that being said, what is it you are trying to really achieve. i think there might be a subtle misunderstanding of the EE architecture as a whole.
you might be able to achieve the goal in a way that does not violate EE platform semantics.
-
4. Re: Thread.sleep in mbean give 100% cpu
chitech Apr 19, 2012 7:31 AM (in response to sfisque)Problem is now solved. No problem with using Thread with ExecuteService in MBean. The problem was another jboss thread which has causing the high cpu load.