1 17 package org.apache.servicemix.locks.impl; 18 19 import org.apache.servicemix.locks.LockManager; 20 21 import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap; 22 import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentMap; 23 import edu.emory.mathcs.backport.java.util.concurrent.locks.Lock; 24 import edu.emory.mathcs.backport.java.util.concurrent.locks.ReentrantLock; 25 26 public class SimpleLockManager implements LockManager { 27 28 private ConcurrentMap locks = new ConcurrentHashMap(); 29 30 public Lock getLock(String id) { 31 Lock lock = (Lock) locks.get(id); 32 if (lock == null) { 33 lock = new ReentrantLock(); 34 Lock oldLock = (Lock) locks.putIfAbsent(id, lock); 35 if (oldLock != null) { 36 lock = oldLock; 37 } 38 } 39 return lock; 40 } 41 42 } 43 | Popular Tags |