Exclusive Read Lock

  GigaSpaces 5.X

Documentation Home
Quick Start Guide
Release Notes

Previous release

  Search Here
Searching GigaSpaces Platform 5.X Documentation

                                               

Summary: To allow a user to block other users from reading an object, a read using exclusive read lock mode with a transaction should be performed.

Overview

A new lock mode has been added to the GigaSpaces locking model – the exclusive read lock (ERL). The ERL is similar to select for update SQL for RDBMS, or update lock with ODBMS.

In the JavaSpaces specification, a read under a transaction does not allow other users to modify the Entry, but it does allow two readers or more to read the same Entry under different transactions. To allow a user to block other users from reading an object, a read using exclusive read lock mode with a transaction should be performed.

The following methods support exclusive read lock when used with a transaction:

  • read()
  • readIfExists()
  • readMultiple()

The exclusive read lock is supported in a clustered environment when using the Jini Transaction Manager.

GigaSpaces locking by API types:

  • Take Lock
  • Update Lock
  • Write Lock
  • Exclusive Read Lock
  • Shared Read Lock
  • No Lock
New in GigaSpaces 5.2
The Exclusive Read Lock is a new feature, supported in GigaSpaces 5.2 and onwards.

Code Example

IJSpace space = (IJSpace) SpaceFinder.find("jini://*/*/mySpace");
space.setReadTakeModifiers(ReadTakeModifiers.EXCLUSIVE_READ_LOCK);
// this will allow all read operations with this proxy to use Exclusive Read Lock mode
Lock lock = new Lock();
lock.key = new Integer(1);
lock.data = "my data";
space.write(lock, null, Lease.FOREVER);
LocalTransactionManager trManager = (LocalTransactionManager)LocalTransactionManager
		.getInstance(space);

Transaction.Created tCreated1 = TransactionFactory.create(trManager, 1000 * 60);
ServerTransaction txn1 = (ServerTransaction)tCreated1.transaction;
Lock lock_template1 = new Lock();
lock_template1.key = new Integer(1);
Lock lock1 = (Lock) space.read(lock_template1, txn1, 1000);
If (lock1!= null)
	System.out.println("Transaction " + txn1.id + " Got exclusive Read Lock on Entry:"
		+ lock1.__getEntryInfo().m_UID);

Wiki Content Tree


Your Feedback Needed!

We need your help to improve this wiki site. If you have any suggestions or corrections, write to us at techw@gigaspaces.com. Please provide a link to the wiki page you are referring to.

Labels

 
(None)