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]
«« Color
»»
# 1

> 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

smreddy_2000 at 2007-6-29 12:19:00 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 2

Hi Hunter

Iam also using a timer.

Iam new at this but trying to create a API Timer that initiates the moment my outgoing voice call starts or network confirms connection.

The midlet is fine but the wake up -push registry is vague to me

Does anybody know what port and URL to use on a mobile phone to get a push from a server connection

confirmation

Please any help

Hugomagic at 2007-6-29 12:19:00 > top of Java-index,Java Mobility Forums,Java ME Technologies...