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

Improved self destructor

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