1 13 14 package org.logicalcobwebs.concurrent; 15 16 178 179 public class SynchronizedVariable implements Executor { 180 181 protected final Object lock_; 182 183 184 public SynchronizedVariable(Object lock) { 185 lock_ = lock; 186 } 187 188 189 public SynchronizedVariable() { 190 lock_ = this; 191 } 192 193 196 public Object getLock() { 197 return lock_; 198 } 199 200 204 205 public void execute(Runnable command) throws InterruptedException { 206 if (Thread.interrupted()) throw new InterruptedException (); 207 synchronized (lock_) { 208 command.run(); 209 } 210 } 211 } 212 | Popular Tags |