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 Atomic Variables versus Synchronization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Atomic Variables versus Synchronization" Watch "Atomic Variables versus Synchronization" New topic
Author

Atomic Variables versus Synchronization

Santosh Kumar Nayak
Ranch Hand

Joined: Aug 02, 2011
Posts: 82
Can we use the Atomocity concept as it is more effective than Synchronized block ?
Chan Ag
Bartender

Joined: Sep 06, 2012
Posts: 839
    
  14
I think you can as long as you can deal with the complexity of converting a synchronized block to a non synchronized atomic program/block/or anything it means as per your changed algorithm. If you have many variables that need to be atomically updated, you may sometimes need to write your own implementation classes and there are chances that you may need to change your algorithm a great deal. Also you may have to test it thoroughly and testing multi-threaded applications is inherently tough.

I'd consider the readwrite locks' suggestion ( if applicable ) posted above.

Chan.
Chan Ag
Bartender

Joined: Sep 06, 2012
Posts: 839
    
  14
Also,

Can we use the Atomocity concept as it is more effective than Synchronized block ?


is a very general ( not sure if it is a correct statement) statement. I'm not sure if atomic classes are more effective though ( remember the extra looping - even though it may be just one extra loop ). I think synchronization should be brief and focused and atomic classes should be used if they don't make your implementation very complex and you need to minimize synchronization. I think there is a trade off here and you can't say one is more effective than the other cause they both achieve different things. May be it depends on what you mean by effective.

Of course, there are more qualified people to talk about it. :-)

Chan.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Atomic Variables versus Synchronization
 
Similar Threads
synchronized context
servlet and thread synchronization
Singleton pattern doubt
static synchronized block
Synchronized block parameter question