1 8 9 package com.sleepycat.je.txn; 10 11 import java.util.Collections ; 12 import java.util.Map ; 13 import java.util.WeakHashMap ; 14 15 import com.sleepycat.je.utilint.Tracer; 16 17 21 public class LockInfo implements Cloneable { 22 private Locker locker; 23 private LockType lockType; 24 25 private static boolean deadlockStackTrace = false; 26 private static Map traceExceptionMap = 27 Collections.synchronizedMap(new WeakHashMap ()); 28 private static class StackTraceAtLockTime extends Exception {} 29 30 33 static void setDeadlockStackTrace(boolean enable) { 34 deadlockStackTrace = enable; 35 } 36 37 40 public static boolean getDeadlockStackTrace() { 41 return deadlockStackTrace; 42 } 43 44 47 public LockInfo(Locker locker, LockType lockType) { 48 this.locker = locker; 49 this.lockType = lockType; 50 51 if (deadlockStackTrace) { 52 traceExceptionMap.put(this, new StackTraceAtLockTime()); 53 } 54 } 55 56 59 void setLocker(Locker locker) { 60 this.locker = locker; 61 } 62 63 66 Locker getLocker() { 67 return locker; 68 } 69 70 73 void setLockType(LockType lockType) { 74 this.lockType = lockType; 75 } 76 77 80 LockType getLockType() { 81 return lockType; 82 } 83 84 public Object clone() 85 throws CloneNotSupportedException { 86 87 return super.clone(); 88 } 89 90 93 public void dump() { 94 System.out.println(this); 95 } 96 97 public String toString() { 98 StringBuffer buf = new StringBuffer (500); 99 100 buf.append("<LockInfo locker=\""); 101 buf.append(locker); 102 buf.append("\" type=\""); 103 buf.append(lockType); 104 buf.append("\"/>"); 105 106 if (deadlockStackTrace) { 107 Exception traceException = (Exception ) traceExceptionMap.get(this); 108 if (traceException != null) { 109 buf.append(" lock taken at: "); 110 buf.append(Tracer.getStackTrace(traceException)); 111 } 112 } 113 114 return buf.toString(); 115 } 116 } 117 | Popular Tags |