This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Ask Threads and Events..  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi everyone, i'm newbie here and with java..
i wanna ask about object that can raise an event.
i have 1 object that has 1 variable which can be changed (public).
if i have 5 threads that access the same variable in this object, and one of them change the variable, can i raise an event, so the other threads know that the value of the variable was changed, and they can do some action?
ok, thx b4.
n sorry if my english make confusing...
 
Ranch Hand
Posts: 472
Linux Objective C Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can, but all other threads should wait for your event so certainly idling. Better solution could be that threads just checking some flag when they need to know if your variable was changed.
 
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your other threads keep working while waiting for the value to change you could look into Observer and Observable. Maybe make a single owner of the "gold data" that all threads listen to for changes.

If your other threads block until the value changes, look at wait() and notifyAll() on Object. All the threads would wait() on the same object and whoever changes it would notify the others.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!