Jef Smith wrote:Matthew,
Could you elaborate on how this works? I thought that when you did something like:
That you are actually starting two threads on the SAME instance.
If t1 and t2 are different instances, is the benefit of multi-threading just that these two instances can work independently but do a similar job because they are the same class?
Sorry if these questions are really dumb but I'm finding the concept of threads very confusing.
Matthew Brown wrote: The question is, do the threads need to interact by sharing state? If they do, then they'd could share a Runnable object - but then you have to make sure they don't stop each other working correctly. If you can make your threads not need to interact with each other, life is easier.
Sorry if these questions are really dumb but I'm finding the concept of threads very confusing.
The biggest gamble will be to ask a question whose answer you know in that it will challenge your theory | www.TechAspire.blogspot.in
Jef Smith wrote:Matthew and Jeff,
Thanks for the great answers. I think my confusion came from thinking that:
was actually:
So, in the second case, if Worker has the method setMyId() the value of myId will be the same
for both t1 and t2 even of the method was only called on t2.
Whereas in the first case nothing
done to t2 will have any effect on t1?
Wanna see my flashlight? How about this tiny ad?
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|