• Post Reply Bookmark Topic Watch Topic
  • New Topic

Find some Thread  RSS feed

 
Marko Debac
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a problem of thinking: I have lots of thread, some of them sleep and some of them are working, and I cant figure out how can I, in the middle of everything, find some thread by name and delete her.

I was thinking that on creation of each thread I put her in arraylist, but can she working her jobs from the list?
somethig like
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, an ArrayList (without restriction by generics) can hold any object, including a thread object. In your example, you can store the thread object directly in the array list. But to answer you question...


To get a thread to exit, it must be cooperative. You should design some sort of mechanism, most common by having the thread check a flag once in a while -- if set, then return from the run() method. You may also want to look into the interrupt() method, which may be able to get the thread to check the flag sooner.

Henry
 
Marko Debac
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have Java Thread 3th Edition book, do you now maybe some kind of similar example exist in those book?
 
Marko Debac
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
p.s. example with those flags..?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!