Created
March 14, 2013 17:07
-
-
Save lincolnthree/5163147 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Override | |
| public Lock obtainLock(LockMode mode) | |
| { | |
| ReadWriteLock readWriteLock = new ReentrantReadWriteLock(true); | |
| if (LockMode.READ.equals(mode)) | |
| return readWriteLock.readLock(); | |
| else | |
| return readWriteLock.writeLock(); | |
| } | |
| @Override | |
| public <T> T performLocked(LockMode mode, Callable<T> task) | |
| { | |
| Assert.notNull(mode, "LockMode must not be null."); | |
| Assert.notNull(task, "Task to perform must not be null."); | |
| Lock lock = obtainLock(mode); | |
| lock.lock(); | |
| T result; | |
| try | |
| { | |
| result = task.call(); | |
| } | |
| catch (Exception e) | |
| { | |
| throw new ContainerException(e); | |
| } | |
| finally | |
| { | |
| lock.unlock(); | |
| } | |
| return result; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment