If an object implements 2 or more threads then will the member variables are shared between these 2 threads?
pascal betz
Ranch Hand
Joined: Jun 19, 2001
Posts: 547
posted
0
if the "variables" are acccessible from one thread, then why shouldnt they be visible to the other thread(s) ? threads are just java objects... same rules apply as with other objects.
if you have multiple threads accessing the same memeber variables, then you need to think about synchronizing access to these members and make sure you really need more than one thread.
p
Stan James
(instanceof Sidekick)
Ranch Hand
Joined: Jan 29, 2003
Posts: 8791
posted
0
An object doesn't so much "implement" multiple threads as it winds up being called by multiple threads. When one object has methods called by two threads, the member variables on that object can be a real problem unless you manage them with synchronization. A class with thorough protection is called "thread safe". Otherwise it is "unsafe" for multi-threading applications.
Try the Sun Thread Tutorial or scroll up to the Threads etc. forum if you want to dig into the details! [ April 02, 2006: Message edited by: Stan James ]
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
ak pillai
author
Ranch Hand
Joined: Feb 11, 2006
Posts: 288
posted
0
For a diagram which depicts what Stan and Pascal stated, look at Q43