• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to access Threads from their names

 
jon rozanski
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here (name referencing threads) they mention a way to reference threads by their name, but yes, it seems much easier to do this with an array
 
Steve Dambrosio
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jon rozanski wrote:Here (name referencing threads) they mention a way to reference threads by their name, but yes, it seems much easier to do this with an array


Yes, you can name threads, but I don't see how that helps you to reference a thread. I've seen thread names used to identify individual threads in log messages, for example. If I want a thread to do my bidding, then I need a reference to it, and that would be a variable, not the thread's name.
 
jon rozanski
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


On that link the show this to reference a thread by name
 
Campbell Ritchie
Sheriff
Pie
Posts: 49849
70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

That does not look a very efficient way to get threads by name. And why would you want to?
It might be better to put the threads and their names (or more precisely the other way round) into a Map<String, Thread>. But again, why would you want to do it?

This appears to be a new question on an old discussion; please don’t do that. I can create a new discussion for the new question, fortunately.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49849
70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the old discussion.
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you could do that. But in my opinion if you expect that you're going to have to work with an object, your design should just keep a reference to that object, instead of trying to scavenge it back from the environment later. You have there a hack which works with Thread objects, but not with any other kind of objects.

And likewise if you're changing your design and you find you have to work with an object which you don't have a handy reference to, then you should change the design in such a way that you start keeping that reference around.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic