The Artima Developer Community
Sponsored Link

Java Answers Forum
Thread

2 replies on 1 page. Most recent reply: Jun 6, 2005 6:25 AM by barron

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Sushma Gadde

Posts: 1
Nickname: sushi
Registered: Jun, 2005

Thread Posted: Jun 6, 2005 3:06 AM
Reply to this message Reply
Advertisement
When I create a thread with a name and create another thread with the same name(Both are objects of same class), I am not getting exception .
Is there any way to get the exception while creating the second thread with same name?
If not, is there any other way to differentiate thread objects (of same calss,same name) with some unique attribute?


Jack

Posts: 10
Nickname: zyppora
Registered: Jan, 2005

Re: Thread Posted: Jun 6, 2005 4:53 AM
Reply to this message Reply
Been awhile since I did Java, but here's what I think:

What you're doing is taking a name, say 'Thread1', and you create a thread, to which the name 'Thread1' points. The thread itself is not affected by whatever name you give it.

However, when you create another thread and you give it the same name, i.e. you have the name 'Thread1' point to the second thread, you will lose the reference to the first thread you created.

It's always good to keep your reference to a thread, or have it run with a user interface (so at least you, if not the script, can get to it in order to kill it eventually).

barron

Posts: 13
Nickname: toniblair
Registered: May, 2005

Re: Thread Posted: Jun 6, 2005 6:25 AM
Reply to this message Reply
"When I create a thread with a name and create another thread with the same name"

what exactly do you mean by this? is it:

Thread t1 = new Thread(target);
Thread t1 = new Thread(target);

or

Thread t1 = new Thread("threadname"); //using String name constructor
Thread t2 = new Thread("threadname"); // using the same name constructor

Jack is correct if you are refering the for first example. But, I am not sure about the second. I don't believe that the Thread name (not object name) has to be unique. In the second example, I believe you would have a reference to both t1 and t2 Threads...

Flat View: This topic has 2 replies on 1 page
Topic: Object Serialisation Previous Topic   Next Topic Topic: java beans

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use