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

Improved self destructor

上级 0f3ef9e3
......@@ -101,7 +101,6 @@ import org.h2.test.synth.TestRandomSQL;
import org.h2.test.synth.TestTimer;
import org.h2.test.synth.sql.TestSynth;
import org.h2.test.synth.thread.TestMulti;
import org.h2.test.unit.SelfDestructor;
import org.h2.test.unit.TestAutoReconnect;
import org.h2.test.unit.TestBitField;
import org.h2.test.unit.TestCache;
......@@ -137,6 +136,7 @@ import org.h2.test.unit.TestValue;
import org.h2.test.unit.TestValueHashMap;
import org.h2.test.unit.TestValueMemory;
import org.h2.test.utils.OutputCatcher;
import org.h2.test.utils.SelfDestructor;
import org.h2.tools.DeleteDbFiles;
import org.h2.tools.Server;
import org.h2.util.MemoryUtils;
......
......@@ -9,7 +9,7 @@ package org.h2.test.db;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.h2.test.unit.SelfDestructor;
import org.h2.test.utils.SelfDestructor;
/**
* A task that can be run as a separate process.
......
......@@ -16,7 +16,7 @@ import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Arrays;
import org.h2.test.unit.SelfDestructor;
import org.h2.test.utils.SelfDestructor;
import org.h2.util.StringUtils;
/**
......
......@@ -20,7 +20,7 @@ import java.util.Random;
import org.h2.test.TestAll;
import org.h2.test.TestBase;
import org.h2.test.unit.SelfDestructor;
import org.h2.test.utils.SelfDestructor;
import org.h2.tools.Backup;
import org.h2.tools.DeleteDbFiles;
import org.h2.util.IOUtils;
......
......@@ -11,7 +11,7 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.h2.test.unit.SelfDestructor;
import org.h2.test.utils.SelfDestructor;
/**
* The application code for the {@link TestHalt} application.
......
......@@ -14,7 +14,7 @@ import java.sql.Statement;
import java.util.Random;
import org.h2.test.TestBase;
import org.h2.test.unit.SelfDestructor;
import org.h2.test.utils.SelfDestructor;
/**
* A random recovery test. This test starts a process that executes random
......
......@@ -13,7 +13,7 @@ import java.util.ArrayList;
import java.util.Random;
import org.h2.store.FileLister;
import org.h2.test.TestBase;
import org.h2.test.unit.SelfDestructor;
import org.h2.test.utils.SelfDestructor;
/**
* Test application for TestKill.
......
......@@ -14,7 +14,7 @@ import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Random;
import org.h2.test.TestBase;
import org.h2.test.unit.SelfDestructor;
import org.h2.test.utils.SelfDestructor;
/**
* Standalone recovery test. A new process is started and then killed while it
......
......@@ -17,7 +17,7 @@ import java.util.Random;
import org.h2.constant.ErrorCode;
import org.h2.test.TestBase;
import org.h2.test.unit.SelfDestructor;
import org.h2.test.utils.SelfDestructor;
import org.h2.tools.Backup;
import org.h2.util.FileUtils;
import org.h2.util.New;
......
......@@ -14,6 +14,7 @@ import java.sql.SQLException;
import org.h2.api.DatabaseEventListener;
import org.h2.test.TestBase;
import org.h2.test.utils.SelfDestructor;
/**
* Tests the flag db_close_on_exit.
......
......@@ -4,10 +4,11 @@
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.test.unit;
package org.h2.test.utils;
import java.lang.reflect.Method;
import java.sql.Timestamp;
import java.util.Map;
/**
* This is a self-destructor class to kill a long running process automatically
......@@ -49,20 +50,23 @@ public class SelfDestructor extends Thread {
String time = new Timestamp(System.currentTimeMillis()).toString();
System.out.println(time + " Killing the process after " + minutes + " minute(s)");
try {
int activeCount = Thread.activeCount();
Thread[] threads = new Thread[activeCount + 100];
int len = Thread.enumerate(threads);
for (int i = 0; i < len; i++) {
Thread t = threads[i];
String threadName = "Thread #" + i + ": " + t.getName();
System.out.println(threadName);
Map<Thread, StackTraceElement[]> map = Thread.getAllStackTraces();
for (Map.Entry<Thread, StackTraceElement[]> en : map.entrySet()) {
System.out.println(en.getKey());
for (StackTraceElement el : en.getValue()) {
System.out.println(" " + el);
}
}
System.out.println();
System.out.flush();
try {
Thread.sleep(1000);
} catch (Exception e) {
// ignore
}
int activeCount = Thread.activeCount();
Thread[] threads = new Thread[activeCount + 100];
int len = Thread.enumerate(threads);
Method stop = Thread.class.getMethod("stop", Throwable.class);
for (int i = 0; i < len; i++) {
Thread t = threads[i];
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论