Results 1 to 4 of 4

Thread: How to create read write lock in java

  1. #1
    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

  2. #2
    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.

  3. #3
    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..

  4. #4
    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.

Similar Threads

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

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,254,954.27926 seconds with 17 queries