All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.scudata.dm.LockManager Maven / Gradle / Ivy

Go to download

SPL(Structured Process Language) A programming language specially for structured data computing.

There is a newer version: 20241126
Show newest version
package com.scudata.dm;

import java.util.HashMap;

/**
 * ??????????????lock(n,s)????
 * @author WangXiaoJun
 *
 */
public final class LockManager {
	private static HashMap lockMap = new HashMap();
	
	/**
	 * ????????ֵ
	 * @param key ??ֵ
	 * @param ms ?ȴ?????????С??0??ʾ??????ʱ
	 * @param ctx ??????????
	 * @return ????ɹ?true??ʧ?ܷ???false
	 */
	public final static Object lock(Object key, long ms, Context ctx) {
		LockObject lock;
		synchronized(lockMap) {
			lock = lockMap.get(key);
			if (lock == null) {
				lock = new LockObject(ctx);
				lockMap.put(key, lock);
			}
		}
		
		if (lock.lock(ms, ctx)) {
			return Boolean.TRUE;
		} else {
			return Boolean.FALSE;
		}
	}
	
	/**
	 * ????????ֵ
	 * @param key ??ֵ
	 * @param ctx
	 * @return true???ɹ???false??ʧ??
	 */
	public final static boolean unLock(Object key, Context ctx) {
		LockObject lock;
		synchronized(lockMap) {
			lock = lockMap.get(key);
			if (lock == null) {
				return false;
			}
		}
		
		return lock.unlock(ctx);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy