Does the thread on which an objects method is executed depend on the thread on the thread in which it is created?
Imagine you have two threads in your java applications Thread1 and Thread2 and two classes ClassA and ClassB.
You create an ObjectOfClassA on Thread1 then you create and ObjectOfClassB on Thread2, the ObjectOfClassB contains a reference to the ObjectOfClassA. When the ObjectOfClassB runs a method of ObjectOfClassA on which thread will the method be executed?
In you answer please provide a link to the relevant documentation.
Based on what I’ve seen I get the sense that the execution of an objects method is completely orthogonal to the thread on which it was created, but I’m not sure.
On the same thread which is running the caller method of ObjectOfClassB itself (that would be Thread2 I guess… but as @Andrzej noted, it can be another, third thread too). This is completely independent of which thread created which object. What matters is only whether or not a given object is published (i.e. made available) to a given thread. If it is, it can be run by that thread.