Thread stopping
HI, I have a question regarding the use of threads in my program.
I have 4 classes which I have implemented as Runnable. Each class uses it's run method to call methods which carry out queries on a database. I have a thread t which I use to run the methods.
publicvoid run()
{
setTotalIncoming();
getTotalOutbound();
setTotalLostCalls();
setTotalCallsSentToVoicemail();
getOutOfHoursVoicemail();
setPercentAnswered();
getTotalPhoneTime();
getTotalTalkTime();
setAverageAnswerTime();
setLostRingingTime();
setVoicemailRingingTime();
getOutOfHoursRingingTime();
}
The problem is that periodically (unspecified time periods), my program calls the refresh() method in my program which re-assigns my thread t. Shown here:
publicvoid refresh()
{
while(isRunning){
// wait for thread to finish
}
t =new Thread(this);
t.start();
}
Now, the problem is that, currently, my program could re-assign t, whilst the run() method wasn't finished executing all it's methods. I think this is causing some unexpected behaviour in my code.
I am noticing this in my ConnectionPool class, which I know is sound, as it is a very similar adaptation on code found in a well known book. Basically my program manages to open more connections that the Maximum no. of connections is set to in the ConnectionPool.
Does anyone have any ideas:
1. How I can ensure that all my methods have finished executing, before I allow the refresh() method to re-assign t.
2. If this problem could cause my connection pool to open more connections than i have set the maximum to.
Thanks in advance for your time, I hope someone can help me!

