Skip to main content

thread issue

4 replies [Last post]
stonehu
Offline
Joined: 2008-03-11
Points: 0

Hi,guys.
I meet a problem:
why some threads can be killed on debug state but can't be killed on release state.
Thank you very much.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Bill Foote

bd-j-dev@mobileandembedded.org wrote:
> Hi,gays.
> I meet a problem:
> why some threads can be killed on debug state but can't be killed on release state.

The proper way of arranging for a thread's termination is
discussed in the HD cookbook under "Xlet termination", on
page 16-3 and 16-4, and illustrated in sample code 16.1.

In short: In multithreaded programming in general (including
in Java), it's a bad idea to try to kill threads forcibly with
some kind of external destroy() method. This is as true in C as
it is in Java -- any good book on POSIX threads will basically
tell you the same thing.

Instead, you have to program the code that's executing in the
thread to gracefully terminate when a condition is true, e.g.
when the containing xlet is being destroyed. The sample code
in 16.1 illustrates the use of a condition variable to do just
that.

Cheers,

Bill

---------------------------------------------------------------------
To unsubscribe, e-mail: bd-j-dev-unsubscribe@hdcookbook.dev.java.net
For additional commands, e-mail: bd-j-dev-help@hdcookbook.dev.java.net

billf
Offline
Joined: 2004-02-13
Points: 0

The proper way of arranging for a thread's termination is
discussed in the HD cookbook under "Xlet termination", on
page 16-3 and 16-4, and illustrated in sample code 16.1.

In short: In multithreaded programming in general (including
in Java), it's a bad idea to try to kill threads forcibly with
some kind of external destroy() method. This is as true in C as
it is in Java -- any good book on POSIX threads will basically
tell you the same thing.

Instead, you have to program the code that's executing in the
thread to gracefully terminate when a condition is true, e.g.
when the containing xlet is being destroyed. The sample code
in 16.1 illustrates the use of a condition variable to do just
that.

Cheers,

Bill

stonehu
Offline
Joined: 2008-03-11
Points: 0

thank you very much,
but i still have a problem.
cvm hang when a xlet deamon thread is alive.
how can i kill this xlet deamon thread before cvm exit.
this thread seems can be killed in debug model but not in release model.
regards

francoislionet
Offline
Joined: 2008-01-13
Points: 0

Hello,

Could you be more specific, like post some code?

Threads are killed when you exit the run() method. You should not use Thread.destroy() as it is deprecated. Instead you should exit gracefully, or in the other thread set a flag indicating the exit and test the flag in you thread loop.

Francois