I’m trying to create a program in java where threads are observable objects and a window is the observer. What I don’t understand is how do I distinguish the several threads, which all do the same thing, from each other on the update method so that I could update their position individually on the window.
Share
As Stated in comment by @PeterLawrey you can use the name argument from the Thread object to set an unique name and then query your Threads and find which one is doing what. The constructor is as follows:
But, for accessing the Threads more easily after it’s executing, and to track I recommend the use of ThreadGroup object. From the api docs:
Therefore, you can use the method public int enumerate(Thread[] list,
boolean recurse)
Which
And
getName()of all threads in the group. I hope it helped. Cheers