Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 05-05-2009
Member
 
Join Date: Apr 2009
Posts: 49
How to create read write lock in java

Hello,

Is it possible to create the read/write lock in Java, and if possible please let me know the procedure for doing so, and to assign the lock should we need to write the get set method with it, also describe with the suitable example.

Thanks in Adavance
Reply With Quote
  #2  
Old 05-05-2009
Member
 
Join Date: Dec 2008
Posts: 161
Re: How to create read write lock in java

A ReadWriteLock maintains a pair of both the read and write lock which we could recommend as an associated locks, one for read-only operations and one for writing. The read lock may be held simultaneously by multiple reader threads that is this lock is used only on those thread which has implemented under the read lock, so long as there are no writers. The write lock is exclusive.

A read-write lock allows for a greater level of concurrency in accessing shared data than that permitted by a mutual exclusion lock.
Reply With Quote
  #3  
Old 05-05-2009
Member
 
Join Date: Dec 2008
Posts: 183
Re: How to create read write lock in java

here I will provide outline for how to create read write lock ,please check below.

Code:
public void getReadLock()
	{
		synchronized(mutex)
		{
                      //Initialize

                      ...
                       ....
                         ....
                 }
         }
public void getWriteLock()
	{
		synchronized(mutex)
		{
                      //Initialize

                      ...
                       ....
                         ....
                 }
         }
Like this you need to set your lock on your created nodes..
Reply With Quote
  #4  
Old 05-05-2009
Member
 
Join Date: Jan 2009
Posts: 124
Re: How to create read write lock in java

Read-write lock in Java allows multiple threads to acquire a read lock provided no other thread simultaneously has a write lock on the same object. A thread may acquire a write lock if no other thread owns either a read lock or a write lock.

The logic for writing or implementing lock will be as follows:

Code:
readLock

Lock readLock()

    Returns the lock used for reading.

    Returns:
        the lock used for reading.

writeLock

Lock writeLock()

    Returns the lock used for writing.

    Returns:
        the lock used for writing.
Hope you will get some idea, how to set the lock.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to create read write lock in java"
Thread Thread Starter Forum Replies Last Post
JAVA beginner: create a screen where i can write messages markafar Software Development 1 19-06-2011 01:00 AM
Read and Write a .txt file with Java Mulan Software Development 4 28-07-2010 02:03 AM
File read-write mode in java ISAIAH Software Development 5 20-01-2010 10:02 AM
How to read and write files in Java BansiJ Software Development 3 02-09-2009 08:52 PM
How to toggle between read-only and read-write in Word 2007 Mae Huckett MS Office Support 1 13-02-2008 02:50 AM


All times are GMT +5.5. The time now is 04:03 AM.