KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > util > concurrent > SynchronizedVariable


1 /*
2  * $Id: SynchronizedVariable.java 3196 2006-09-24 22:50:50Z holger $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
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 edu.emory.mathcs.backport.java.util.concurrent.Executor;
14
15 // @ThreadSafe
16
public abstract class SynchronizedVariable implements Executor
17 {
18     // @GuardedBy(itself)
19
protected final Object JavaDoc _lock;
20
21     public SynchronizedVariable()
22     {
23         super();
24         _lock = this;
25     }
26
27     public SynchronizedVariable(Object JavaDoc lock)
28     {
29         super();
30         _lock = lock;
31     }
32
33     public Object JavaDoc getLock()
34     {
35         return _lock;
36     }
37
38     public void execute(Runnable JavaDoc command)
39     {
40         synchronized (_lock)
41         {
42             command.run();
43         }
44     }
45
46 }
47
Popular Tags