View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.util.concurrent;
8   
9   import edu.emory.mathcs.backport.java.util.concurrent.Executor;
10  
11  // @ThreadSafe
12  public abstract class AbstractSynchronizedVariable implements Executor
13  {
14      // @GuardedBy(itself)
15      protected final Object lock;
16  
17      public AbstractSynchronizedVariable()
18      {
19          super();
20          lock = this;
21      }
22  
23      public AbstractSynchronizedVariable(Object lock)
24      {
25          super();
26          this.lock = lock;
27      }
28  
29      public Object getLock()
30      {
31          return lock;
32      }
33  
34      public void execute(Runnable command)
35      {
36          synchronized (lock)
37          {
38              command.run();
39          }
40      }
41  
42  }