Java ReentrantLock getLock(String id)

Here you can find the source of getLock(String id)

Description

get Lock

License

Open Source License

Declaration

public static Lock getLock(String id) 

Method Source Code

//package com.java2s;
/**//from w w w.j  a va2  s.c  om
 * Project: taurus-agent
 * 
 * File Created at 2013-5-21
 * $Id$
 * 
 * Copyright 2013 dianping.com.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Dianping Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with dianping.com.
 */

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Main {
    private static Map<String, Lock> idToLockMap = new HashMap<String, Lock>();

    public static Lock getLock(String id) {
        synchronized (idToLockMap) {
            Lock lock = idToLockMap.get(id);
            if (lock == null) {
                lock = new ReentrantLock();
                idToLockMap.put(id, lock);
            }
            return lock;
        }
    }
}

Related

  1. getActivityLock()
  2. getAudioLock()
  3. getLockInfo(ReentrantLock lock)
  4. isRepair()
  5. lock()
  6. readSyncLock(String id)