The documentation for java.util.Timer says the following:
"However, this can take arbitrarily long to occur. By default, the task
execution thread does not run as a daemon thread, so it is capable of
keeping an application from terminating."
(thes are the MIDP api docs, but I think it's the same in the regular
edition)
I want the task execution thread to executre as a daemon thread, but
there's no way I can see of doing this, despite the hint in the docs
above that it is possible (i.e it says "by default...")
Any ideas?
thanks,
lex
Domagoj Klepac - 24 May 2006 12:26 GMT
>The documentation for java.util.Timer says the following:
>
[quoted text clipped - 9 lines]
>above that it is possible (i.e it says "by default...")
>Any ideas?
"After the last live reference to a Timer object goes away and all
outstanding tasks have completed execution, the timer's task execution
thread terminates gracefully (and becomes subject to garbage
collection)."
That means that timer execution task will keep your application from
terminating only if it is currently executing one of your tasks. If
tasks are pending, but are not yet executed, the timer execution
thread _will_ terminate gracefully.
So if you keep your timer tasks short, you have nothing to worry -
actually, it's pretty nice that timer execution thread is not a daemon
thread. That means that your tasks are not abruptly stopped if
application shuts down when they're executed, possibly leaving your
tasks in unstable state.
Domchi

Signature
Ouroboros ltd. - http://www.ouroboros.hr
Antispam: to reply, remove extra monkey from reply-to address.
Thomas Hawtin - 24 May 2006 12:33 GMT
> The documentation for java.util.Timer says the following:
>
[quoted text clipped - 8 lines]
> there's no way I can see of doing this, despite the hint in the docs
> above that it is possible (i.e it says "by default...")
MIDP/CLDC doesn't yet appear to support daemon threads, so Timer has no
chance. You should call cancel on the Timer instead. A bit C++, but you
can't have everything done for you.
Presumably implementations use some sort of native implementation for
Timer. Under Java SE, a finaliser (evil) kills off timer threads of
unreachable timers. CLDC has neither finalisers nor reference queues.
Tom Hawtin

Signature
Unemployed English Java programmer
http://jroller.com/page/tackline/