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

pro.jk.ejoker.common.system.wrapper.RWLockWrapper Maven / Gradle / Ivy

There is a newer version: 3.0.7.1
Show newest version
package pro.jk.ejoker.common.system.wrapper;

import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

import pro.jk.ejoker.common.system.functional.IFunction;
import pro.jk.ejoker.common.system.wrapper.WrapperAssembler.RWLockProviderContext;

public final class RWLockWrapper {
	
	private final static AtomicBoolean hasRedefined = new AtomicBoolean(false);
	
	private static IFunction lockCreator = null;

	public static ReadWriteLock createRWLock() {
		return lockCreator.trigger();
	}
	
	static {
		lockCreator = ReentrantReadWriteLock::new;
		
		WrapperAssembler.setRWLockProviderContext(new RWLockProviderContext() {
			@Override
			public boolean hasBeesSet() {
				return !hasRedefined.compareAndSet(false, true);
			}
			@Override
			public void apply2rwLockCreator(IFunction lockCreator) {
				RWLockWrapper.lockCreator = lockCreator;
			}
		});
	}
	
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy