Interaction between threads
posted 12 years ago
Well, obviously, you'll need a shared collection of all the currently-active balls. This could be a static variable of the BallThread class, and the BallThread constructor could add items to it, but if you ever have balls cease to exist, it'll be tricky to figure out when to remove items from the collection. Perhaps a better solution is that your main program (or the Model component thereof) maintains a collection of currently active balls. Methods to add and delete balls will need to be synchronized, or (I guess) you could use something like Collections.synchronizedSet.