Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Timed threading

  Asked By: Jesse    Date: Apr 29    Category: Java    Views: 500

is it possible in Java to terminate/kill/stop (whatever the appropriate
term is) a thread after it has exceeded an specific allowable time

example...i will kill a thread if it's still alive after 20 minutes



2 Answers Found

Answer #1    Answered By: Mae Roberts     Answered On: Apr 29

may be you could using timer, it has schedule method to define how long the
thread should run.

Answer #2    Answered By: Freda Lane     Answered On: Apr 29

this depends on what you are trying to do.
If your application creates their own threads (to do some
parallel processing e.g.) then you can of course kill
this thread  inside your application (since you are
the owner).
If you are talking about threads in a linux/unix world then
you take a look at the Runtime class in Java which gives
you the ability to call "system commands" like cp, rm, kill  and so on.

Didn't find what you were looking for? Find more on Timed threading Or get search suggestion and latest updates.