提交 c6ce63d8 authored 作者: Thomas Mueller's avatar Thomas Mueller

Formatting (spaces instead of tabs and so on)

上级 94312cca
...@@ -49,6 +49,10 @@ import org.h2.value.Value; ...@@ -49,6 +49,10 @@ import org.h2.value.Value;
*/ */
public class MVTable extends TableBase { public class MVTable extends TableBase {
public static final DebuggingThreadLocal<String> WAITING_FOR_LOCK = new DebuggingThreadLocal<String>();
public static final DebuggingThreadLocal<ArrayList<String>> EXCLUSIVE_LOCKS = new DebuggingThreadLocal<ArrayList<String>>();
public static final DebuggingThreadLocal<ArrayList<String>> SHARED_LOCKS = new DebuggingThreadLocal<ArrayList<String>>();
private MVPrimaryIndex primaryIndex; private MVPrimaryIndex primaryIndex;
private final ArrayList<Index> indexes = New.arrayList(); private final ArrayList<Index> indexes = New.arrayList();
private long lastModificationId; private long lastModificationId;
...@@ -58,10 +62,6 @@ public class MVTable extends TableBase { ...@@ -58,10 +62,6 @@ public class MVTable extends TableBase {
private final ConcurrentHashMap<Session, Session> lockSharedSessions = private final ConcurrentHashMap<Session, Session> lockSharedSessions =
new ConcurrentHashMap<Session, Session>(); new ConcurrentHashMap<Session, Session>();
public static final DebuggingThreadLocal<String> WAITING_FOR_LOCK = new DebuggingThreadLocal<String>();
public static final DebuggingThreadLocal<ArrayList<String>> EXCLUSIVE_LOCKS = new DebuggingThreadLocal<ArrayList<String>>();
public static final DebuggingThreadLocal<ArrayList<String>> SHARED_LOCKS = new DebuggingThreadLocal<ArrayList<String>>();
/** /**
* The queue of sessions waiting to lock the table. It is a FIFO queue to * The queue of sessions waiting to lock the table. It is a FIFO queue to
* prevent starvation, since Java's synchronized locking is biased. * prevent starvation, since Java's synchronized locking is biased.
......
...@@ -9,7 +9,6 @@ import java.util.ArrayList; ...@@ -9,7 +9,6 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import org.h2.api.ErrorCode; import org.h2.api.ErrorCode;
import org.h2.api.TableEngine;
import org.h2.command.ddl.CreateTableData; import org.h2.command.ddl.CreateTableData;
import org.h2.constraint.Constraint; import org.h2.constraint.Constraint;
import org.h2.engine.Database; import org.h2.engine.Database;
...@@ -27,7 +26,6 @@ import org.h2.mvstore.db.MVTableEngine; ...@@ -27,7 +26,6 @@ import org.h2.mvstore.db.MVTableEngine;
import org.h2.table.RegularTable; import org.h2.table.RegularTable;
import org.h2.table.Table; import org.h2.table.Table;
import org.h2.table.TableLink; import org.h2.table.TableLink;
import org.h2.util.JdbcUtils;
import org.h2.util.New; import org.h2.util.New;
/** /**
......
...@@ -248,7 +248,7 @@ public class Sequence extends SchemaObjectBase { ...@@ -248,7 +248,7 @@ public class Sequence extends SchemaObjectBase {
boolean needsFlush = false; boolean needsFlush = false;
long retVal; long retVal;
long flushValueWithMargin = -1; long flushValueWithMargin = -1;
synchronized(this) { synchronized (this) {
if ((increment > 0 && value >= valueWithMargin) || if ((increment > 0 && value >= valueWithMargin) ||
(increment < 0 && value <= valueWithMargin)) { (increment < 0 && value <= valueWithMargin)) {
valueWithMargin += increment * cacheSize; valueWithMargin += increment * cacheSize;
......
...@@ -23,36 +23,39 @@ import org.h2.mvstore.db.MVTable; ...@@ -23,36 +23,39 @@ import org.h2.mvstore.db.MVTable;
* Detects deadlocks between threads. Prints out data in the same format as the CTRL-BREAK handler, * Detects deadlocks between threads. Prints out data in the same format as the CTRL-BREAK handler,
* but includes information about table locks. * but includes information about table locks.
*/ */
public class ThreadDeadlockDetector public class ThreadDeadlockDetector {
{
private static String INDENT = " ";
private final ThreadMXBean tmbean; private static final String INDENT = " ";
private final Timer threadCheck = new Timer("ThreadDeadlockDetector", true/* isDaemon */); private static ThreadDeadlockDetector detector;
private static ThreadDeadlockDetector detector = null; private final ThreadMXBean tmbean;
public synchronized static void init() { // a daemon thread
if (detector == null) { private final Timer threadCheck = new Timer("ThreadDeadlockDetector", true);
detector = new ThreadDeadlockDetector();
}
}
private ThreadDeadlockDetector() { private ThreadDeadlockDetector() {
this.tmbean = ManagementFactory.getThreadMXBean(); this.tmbean = ManagementFactory.getThreadMXBean();
// delay: 10 ms
// period: 10000 ms (100 seconds)
threadCheck.schedule(new TimerTask() { threadCheck.schedule(new TimerTask() {
@Override @Override
public void run() { public void run() {
checkForDeadlocks(); checkForDeadlocks();
} }
}, 10/*delay(ms)*/, 10000/*period(ms)*/); }, 10, 10000);
}
public static synchronized void init() {
if (detector == null) {
detector = new ThreadDeadlockDetector();
}
} }
/** /**
* Checks if any threads are deadlocked. If any, print the thread dump information. * Checks if any threads are deadlocked. If any, print the thread dump information.
*/ */
private void checkForDeadlocks() { void checkForDeadlocks() {
long[] tids = tmbean.findDeadlockedThreads(); long[] tids = tmbean.findDeadlockedThreads();
if (tids == null) { if (tids == null) {
return; return;
...@@ -63,11 +66,11 @@ public class ThreadDeadlockDetector ...@@ -63,11 +66,11 @@ public class ThreadDeadlockDetector
print.println("ThreadDeadlockDetector - deadlock found :"); print.println("ThreadDeadlockDetector - deadlock found :");
final ThreadInfo[] infos = tmbean.getThreadInfo(tids, true, true); final ThreadInfo[] infos = tmbean.getThreadInfo(tids, true, true);
final HashMap<Long,String> mvtableWaitingForLockMap = final HashMap<Long, String> mvtableWaitingForLockMap =
MVTable.WAITING_FOR_LOCK.getSnapshotOfAllThreads(); MVTable.WAITING_FOR_LOCK.getSnapshotOfAllThreads();
final HashMap<Long,ArrayList<String>> mvtableExclusiveLocksMap = final HashMap<Long, ArrayList<String>> mvtableExclusiveLocksMap =
MVTable.EXCLUSIVE_LOCKS.getSnapshotOfAllThreads(); MVTable.EXCLUSIVE_LOCKS.getSnapshotOfAllThreads();
final HashMap<Long,ArrayList<String>> mvtableSharedLocksMap = final HashMap<Long, ArrayList<String>> mvtableSharedLocksMap =
MVTable.SHARED_LOCKS.getSnapshotOfAllThreads(); MVTable.SHARED_LOCKS.getSnapshotOfAllThreads();
for (ThreadInfo ti : infos) { for (ThreadInfo ti : infos) {
printThreadInfo(print, ti); printThreadInfo(print, ti);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论