aspose file tools*
The moose likes Java in General and the fly likes How to access Threads from their names Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to access Threads from their names" Watch "How to access Threads from their names" New topic
Author

How to access Threads from their names

jon rozanski
Greenhorn

Joined: Dec 04, 2012
Posts: 5
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

Joined: Apr 02, 2009
Posts: 28
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

Joined: Dec 04, 2012
Posts: 5


On that link the show this to reference a thread by name
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
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

Joined: Oct 13, 2005
Posts: 40052
    
  28
This is the old discussion.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18989
    
    8

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to access Threads from their names