Forums Register Login

Shared object / concurrency

+Pie Number of slices to send: Send
Hi folks,

I have an object that is shared by several threads and is an observer. This object has the following methods:



Considering several threads share this object to invoke the execute() method and that the update() method is receiving thousands of notifications from the observable, do I need to synchronize the code inside mehotd update, like this:



Thanks a lot!

+Pie Number of slices to send: Send
I certainly would.

Note that there is a lot that could be going on in the Observers, you certainly don't want multiple Threads doing this "simultaneously."

Bill
+Pie Number of slices to send: Send
Hi Bill,

I've synchronized and it seems it is working.

Thanks!
+Pie Number of slices to send: Send
 

it seems it is working.



Well thats the tricky thing about multi-threaded programming - it is realllllly hard to test all possible sequences of events for potential collision.

Bill
Proudly marching to the beat of a different kettle of fish... while reading this tiny ad
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1093 times.
Similar Threads
Observable not working properly...
what is Observable class and Observer interface
Observer/Observeable Channel
not using any loops
sending inbetween in observer
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 18, 2024 23:35:27.