org.kuali.rice.core.util
Class ConcurrencyDetector

java.lang.Object
  extended by org.kuali.rice.core.util.ConcurrencyDetector

public class ConcurrencyDetector
extends Object

Utility class that can be used to diagnose concurrency issues. When concurrency is detected the default onConcurrencyDetected() implementation logs an error and optionally the stack traces (if trackStacktraces is enabled). E.g. private static final ConcurrencyDetector detector = new ConcurrencyDetector("Concurrency in Foo class"); public void questionableMethod() { detector.enter(); try { // method impl } finally { detector.exit(); } }

Author:
Kuali Rice Team (rice.collab@kuali.org)

Field Summary
private  ThreadLocal<Boolean> ACQUIRED_SEMAPHORE
           
private  Throwable entryPoint
           
private  org.apache.log4j.Logger log
           
private  String name
           
private  Semaphore semaphore
           
private  boolean trackStacktraces
           
 
Constructor Summary
ConcurrencyDetector()
           
ConcurrencyDetector(String name)
           
ConcurrencyDetector(String name, boolean trackStacktraces)
           
 
Method Summary
 boolean enter()
           
 void exit()
           
protected  void onConcurrencyDetected()
          Logs an error (and optionally stack traces) when concurrency is detected.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ACQUIRED_SEMAPHORE

private ThreadLocal<Boolean> ACQUIRED_SEMAPHORE

log

private final org.apache.log4j.Logger log

name

private final String name

trackStacktraces

private final boolean trackStacktraces

semaphore

private final Semaphore semaphore

entryPoint

private Throwable entryPoint
Constructor Detail

ConcurrencyDetector

public ConcurrencyDetector()

ConcurrencyDetector

public ConcurrencyDetector(String name)

ConcurrencyDetector

public ConcurrencyDetector(String name,
                           boolean trackStacktraces)
Method Detail

enter

public boolean enter()

exit

public void exit()

onConcurrencyDetected

protected void onConcurrencyDetected()
Logs an error (and optionally stack traces) when concurrency is detected. Subclasses may override for custom behavior.



Copyright © 2004-2011 The Kuali Foundation. All Rights Reserved.