Link to home
Start Free TrialLog in
Avatar of bachra04
bachra04Flag for Canada

asked on

flush a failed JMX connection

I connect to a server using JMX connection periodically each 10 sec.
using JMXConnectorFactory.connect
when I unplug the network cable and plug it again ket's say after 20 seconds, seems like there exist more than one connection is already alive.
I want to flush memory if I tried a failed connection so when I plug again the cable I only have one connection not several connections.
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Do you shut down the client cleanly?
make sure you are catching all exceptions (and not ignoring any) and handling them correctly.
Avatar of bachra04

ASKER

Actually the problem I have is this:

I have two threads:

The timer thread and the daemon thread.

The daemon thread has a queue of events and periodically checks this queue to pop events and handle them.

When the daemon receives a TIME OUT event, it makes a JMX connection to get some data.

The problem happens when there is a network problem, at this time since the daemon spends a lot of time trying to make a JMX connection; meanwhile the timer just put another TIME OUT event in the queue and by the time the connection is restored the daemon ends up with 4 or 5 TIME OUT events in his queue and processes them one after the other.

This threading model is not done by me and I shouldnt change at least right now.
I need a good solution to avoid this accumulation of TIME OUT events in the queue.
You have to know that queue is also holding other kinds of events (config change event&) so that the daemon can handle them.
you need to limit your queu to only hold one tiomeout at a time, for example by a check when timeouts are added.
What causes the TIME OUT?
or maybe stop the timer while trying to make a connection
I need to use wait and signal in the same way used in C++.
just to let the timer waiting before sending the event till he gets notified by the daemon.
Do you know how to do it in java?
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
:-)