• Post Reply Bookmark Topic Watch Topic
  • New Topic

Interaction between threads  RSS feed

 
Svetlana Lazareva
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have some balls running in different threads, but I want them to bounce one from another. What model of iteraction can you suggest?
Thanks
 
Stephen Bloch
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!