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.
LVL 2
bachra04Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
Do you shut down the client cleanly?
0
objectsCommented:
make sure you are catching all exceptions (and not ignoring any) and handling them correctly.
0
bachra04Author Commented:
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.
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

objectsCommented:
you need to limit your queu to only hold one tiomeout at a time, for example by a check when timeouts are added.
0
CEHJCommented:
What causes the TIME OUT?
0
objectsCommented:
or maybe stop the timer while trying to make a connection
0
bachra04Author Commented:
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?
0
CEHJCommented:
Just make your daemon own a BlockingQueue. When it's full, the timer thread, offering, will not be able to enqueue

http://java.sun.com/javase/6/docs/api/java/util/concurrent/ArrayBlockingQueue.html
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CEHJCommented:
:-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.