MIDP Timer taks:

A

Alex Hunsley

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
 
D

Domagoj Klepac

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?

"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
 
T

Thomas Hawtin

Alex said:
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...")

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top