Timers... Never stop .... :( :(
Is any one else using timer in their apps?
I am using a timer to track "Connection time out". Here is what I am doing:
private Timerm_timeOutTimer= new Timer();
public HttpConnection getConnection( String m_servletURL ) throws
NetErrorException
{
[...]
m_timeOutTimer.schedule( new throwConnectionTimeOutAlert(),
MAX_TIME_OUT);
}
public void close( Class sender )
{
[...]
m_activeConnection.close();
m_timeOutTimer.cancel();
m_timeOutTimer = null; // just in case set it to null and force
garbage collection?
[...]
}
I verified that the close method is getting called. However, my timer is
still ALIVE !!!! :(... And even though the garbage collection should be
picking up this "timedConnection" object since it is no longer used after
calling close, it is still alive. I guess because of the timer?.
Any thoughts sudgestions or ideas. Looks to me like the cancel method is not
working !!! Could this be possible ? Any help appreciated.
Thanks in advanced
F.Hunter
SurvivorSoft.com
[1167 byte] By [
fmhunter] at [2007-9-26 3:41:56]

> Is any one else using timer in their apps?
>
> I am using a timer to track "Connection time out".
> Here is what I am doing:
>
> private Timerm_timeOutTimer= new Timer();
>
> public HttpConnection getConnection( String
> m_servletURL ) throws
> NetErrorException
> {
> [...]
> m_timeOutTimer.schedule( new
> ( new throwConnectionTimeOutAlert(),
> MAX_TIME_OUT);
> }
>
> public void close( Class sender )
> {
> [...]
> m_activeConnection.close();
> m_timeOutTimer.cancel();
> m_timeOutTimer = null; // just in case set it
> set it to null and force
> garbage collection?
> [...]
> }
>
> I verified that the close method is getting called.
> However, my timer is
> still ALIVE !!!! :(... And even though the garbage
> collection should be
> picking up this "timedConnection" object since it is
> no longer used after
> calling close, it is still alive. I guess because of
> the timer?.
>
> Any thoughts sudgestions or ideas. Looks to me like
> the cancel method is not
> working !!! Could this be possible ? Any help
> appreciated.
>
> Thanks in advanced
>
> F.Hunter
> SurvivorSoft.com
>
Hi hunter,
One way you could overcome this problem is to use the cancel method in TimerTask class. To do so you should store the reference of throwConnectionTimeOutAlert() and call the cancel method in close() method.
ie.,
private Timerm_timeOutTimer= new Timer();
private throwConnectionTimeOutAlert objTemp = new throwConnectionTimeOutAlert();
public HttpConnection getConnection( String
m_servletURL ) throws
NetErrorException
{
[...]
m_timeOutTimer.schedule(objTemp, MAX_TIME_OUT);
}
public void close( Class sender )
{
[...]
m_activeConnection.close();
objTemp.cancel();
obTemp = null;
m_timeOutTimer.cancel();
m_timeOutTimer = null; // just in case set it
set it to null and force
garbage collection?
[...]
}
Goodday,
S.M.Reddy