• Post Reply Bookmark Topic Watch Topic
  • New Topic

Synchronization query

 
Manikandan Swaminathan
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can we implement synchronization in a multi-threaded environment without using the "synchronized" keyowrd?

Request to supplement your answers with code examples.

Thanks in advance.
 
Chris Hurst
Ranch Hand
Posts: 443
3
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can do it but why would you want to ? your reason drives the selection of the alternative, but the fact you have to ask the questions tends to suggest you would be better of using synchronized.

e.g. look at Java ReadWriteLock
 
Henry Wong
author
Sheriff
Posts: 22542
109
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chris Hurst wrote:
e.g. look at Java ReadWriteLock


The java.util.concurrent.locks.ReentrantLock class is probably an implementation that is better to use -- as alternative to synchronization.

Henry
 
Istvan Kovacs
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"synchronization" is a broad term. The solution depends on what you need.
Implicit locks (such as those mentioned by previous posters), Semaphore, Latch, Barrier are all synchronization devices. A Queue (BlockingQueue) is also a way to synchronize operations.
Check java.util.concurrent, and/or read Java Concurrency in Practice.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!