package ch.eitchnet.xmlpers.objref;

import java.text.MessageFormat;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ch.eitchnet.utils.helper.StringHelper;
import ch.eitchnet.xmlpers.api.XmlPersistenceException;

public class LockableObject {

	private static final Logger logger = LoggerFactory.getLogger(LockableObject.class);
	private static long tryLockTime = 10000L;

	private final ReentrantLock lock;

	public LockableObject() {
		this.lock = new ReentrantLock(true);
	}

	public static long getLockTime() {
		return tryLockTime;
	}
	
	public boolean isLockedByCurrentThread() {
		return this.lock.isHeldByCurrentThread();
	}

	/**
	 * @see java.util.concurrent.locks.ReentrantLock#tryLock(long, TimeUnit)
	 */
	public void lock() {
		try {

			logger.info("locking " + this.toString()); //$NON-NLS-1$
			if (!this.lock.tryLock(tryLockTime, TimeUnit.MILLISECONDS)) {
				String msg = "Failed to acquire lock after {0} for {1}"; //$NON-NLS-1$
				msg = MessageFormat.format(msg, StringHelper.formatMillisecondsDuration(tryLockTime), this.toString());
				throw new XmlPersistenceException(msg);
			}
		} catch (InterruptedException e) {
			throw new XmlPersistenceException("Thread interrupted: " + e.getMessage(), e); //$NON-NLS-1$
		}
	}

	/**
	 * @see java.util.concurrent.locks.ReentrantLock#unlock()
	 */
	public void unlock() {
		this.lock.unlock();
		logger.info("unlocking " + this.toString()); //$NON-NLS-1$
	}
}

@@ -851,68 +851,8 @@
  %7B%0A%0A
-%09%09%09logger.info(%22locking %22 + this.toString()); //$NON-NLS-1$%0A
 %09%09%09i
@@ -1144,16 +1144,75 @@
 );%0A%09%09%09%7D%0A
+%09%09%09logger.info(%22locked %22 + this.toString()); //$NON-NLS-1$%0A
 %09%09%7D catc

Update LockableObject.java