Real Pigs wrote:Since there is only 1 instance of MyRunnable, how can it be used as the target in multiple threads?
That's kind of hard to answer, since using objects is normal behaviour in
Java and it's perfectly normal to pass references to objects around without having to deal with arbitrary rules about who can get the references and who can't.
Won't this cause the data in the run method to become corrupted?
No, it couldn't. The data in the run method -- I will interpret that as if you said "the local variables in the run method" -- belong to the
thread which is using the MyRunnable object. So if there are three threads using the object at the same time, each of them has their own copy of those local variables.
However if you had asked "Won't this cause the data in the MyRunnable object to become corrupted?" then the answer would be different. In this case there's only one MyInstance object, and hence only one copy of its instance variables. And yes, each of the three threads could be accessing those variables at the same time, and bad things could happen if those accesses happened in an uncontrolled way.