Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2006

Tip: Looking for answers? Try searching our database.

thread help

Thread view: 
jammytech@gmail.com - 29 May 2006 18:40 GMT
I'm a newbie to java and I have the following Q -

class mythread implements Runnable {

.
.
.

}

scenario 1

mythread my = new mythread();
Thread t1 = new Thread(my);
Thread t2 = new Thread(my);
t1.start();
t2.start();

scenario 2

mythread my1 = new mythread();
mythread my2 = new mythread();
Thread t1 = new Thread(my1);
Thread t2 = new Thread(my2);
t1.start();
t2.start();

Whats the difference b/w scenario 1 and 2 ?. I'm kind of confused here.
Debugger shows me that two threads are created in both scenarios.

-j
VisionSet - 29 May 2006 18:48 GMT
> scenario 1
>
[quoted text clipped - 15 lines]
> Whats the difference b/w scenario 1 and 2 ?. I'm kind of confused here.
> Debugger shows me that two threads are created in both scenarios.

1/ You create a single instance and run it as 2 threads. So changes made to
instance variables in one thread will be seen by the other thread.
2/ You create two instances of the same class and run them as 2 separate
threads.  So instance variables are not shared, but static members of course
still will be.

--
Mike W


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.