File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes Shared object / concurrency Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "Shared object / concurrency" Watch "Shared object / concurrency" New topic
Author

Shared object / concurrency

Rafael Z. Frantz
Greenhorn

Joined: Mar 09, 2010
Posts: 20
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!

This message was edited 1 time. Last update was at by Rafael Z. Frantz

William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 11691
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

Java Resources at www.wbrogden.com
Rafael Z. Frantz
Greenhorn

Joined: Mar 09, 2010
Posts: 20
Hi Bill,

I've synchronized and it seems it is working.

Thanks!
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 11691
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
 
 
subject: Shared object / concurrency
 
MyEclipse, The Clear Choice

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture