View Javadoc

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