/** Constructor for those who wish to do some custom additional tasks * whenever an action or runnable is executed in the {@link Mutex}. This * may be useful for wrapping all the actions with custom {@link ThreadLocal} * value, etc. Just implement the {@link Executor}'s <code>execute(Runnable)</code> * method and do pre and post initialization tasks before running the runnable. * <p> * The {@link Executor#execute} method shall return only when the passed in * {@link Runnable} is finished, otherwise methods like {@link Mutex#readAccess(Action)} and co. * might not return proper result. * * @param privileged can enter privileged states of this Mutex * @param executor allows to wrap the work of the mutex with a custom code * @since 7.12 */ public Mutex(Privileged privileged, Executor executor) { LOCK = new Mutex(privileged); this.wrapper = executor; }
using (Mutex m = new Mutex(false, "Global\\TheNameOfTheMutex")) { // If you want to wait for 5 seconds for other page to finish, // you can do m.WaitOne(TimeSpan.FromSeconds(5),false) if (!m.WaitOne(TimeSpan.Zero, false)) Response.Write("Another Page is updating database."); else UpdateDatabase(); }
/** Constructor for those who wish to do some custom additional tasks * whenever an action or runnable is executed in the {@link Mutex}. This * may be useful for wrapping all the actions with custom {@link ThreadLocal} * value, etc. Just implement the {@link Executor}'s <code>execute(Runnable)</code> * method and do pre and post initialization tasks before running the runnable. * <p> * The {@link Executor#execute} method shall return only when the passed in * {@link Runnable} is finished, otherwise methods like {@link Mutex#readAccess(Action)} and co. * might not return proper result. * * @param privileged can enter privileged states of this Mutex * @param executor allows to wrap the work of the mutex with a custom code * @since 7.12 */ public Mutex(Privileged privileged, Executor executor) { LOCK = new Mutex(privileged); this.wrapper = executor; }
/** Constructor for those who wish to do some custom additional tasks * whenever an action or runnable is executed in the {@link Mutex}. This * may be useful for wrapping all the actions with custom {@link ThreadLocal} * value, etc. Just implement the {@link Executor}'s <code>execute(Runnable)</code> * method and do pre and post initialization tasks before running the runnable. * <p> * The {@link Executor#execute} method shall return only when the passed in * {@link Runnable} is finished, otherwise methods like {@link Mutex#readAccess(Action)} and co. * might not return proper result. * * @param privileged can enter privileged states of this Mutex * @param executor allows to wrap the work of the mutex with a custom code * @since 7.12 */ public Mutex(Privileged privileged, Executor executor) { LOCK = new Mutex(privileged); this.wrapper = executor; }
private Mutex getRepoMutex(String repoId) { synchronized (repoMutexMap) { Mutex m = repoMutexMap.get(repoId); if (m == null) { m = new Mutex(); repoMutexMap.put(repoId, m); } return m; } }
private final Mutex lock = new Mutex(); private final String taskId;
@NonNull @Override public Mutex getMutex( final boolean autoSave, @NonNull final Project project, @NonNull final Project... otherProjects) { return new Mutex(new MutexImpl( this, autoSave, project, otherProjects)); }