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

Automated build improvements.

上级 1cba07fa
......@@ -48,47 +48,54 @@ public class SelfDestructor extends Thread {
// ignore
}
}
String time = new Timestamp(System.currentTimeMillis()).toString();
System.out.println(time + " Killing the process after " + minutes + " minute(s)");
try {
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);
String time = new Timestamp(System.currentTimeMillis()).toString();
System.out.println(time + " Killing the process after " + minutes + " minute(s)");
try {
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];
String threadName = "Thread #" + i + ": " + t.getName();
Error e = new Error(threadName);
if (t != Thread.currentThread()) {
stop.invoke(t, e);
t.interrupt();
}
}
} catch (Throwable t) {
t.printStackTrace();
// ignore
}
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];
String threadName = "Thread #" + i + ": " + t.getName();
Error e = new Error(threadName);
if (t != Thread.currentThread()) {
stop.invoke(t, e);
t.interrupt();
}
}
System.out.println("Killing the process now");
} catch (Throwable t) {
t.printStackTrace();
// ignore
}
try {
Thread.sleep(1000);
} catch (Exception e) {
// ignore
try {
t.printStackTrace(System.out);
} catch (Throwable t2) {
// ignore (out of memory)
}
}
System.out.println("Killing the process now");
Runtime.getRuntime().halt(1);
}
};
......
......@@ -112,12 +112,12 @@ public class UploadBuild {
int end = testOutput.indexOf("<br />", idx);
if (end >= 0) {
String result = testOutput.substring(idx + "Statements per second: ".length(), end);
now += " (" + result + " op/s)";
now += " " + result + " op/s";
}
}
String sql = "insert into item(title, issued, desc) values('Build " + now +
(error ? " (FAILED)" : "") +
(coverageFailed ? " (COVERAGE)" : "") +
(error ? " FAILED" : "") +
(coverageFailed ? " COVERAGE" : "") +
"', '" + ts + "', '<a href=\"http://www.h2database.com/html/testOutput.html\">Output</a>" +
" - <a href=\"http://www.h2database.com/coverage/overview.html\">Coverage</a>" +
" - <a href=\"http://www.h2database.com/automated/h2-latest.jar\">Jar</a>');\n";
......
/*
* Copyright 2004-2013 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.dev.util;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map.Entry;
import java.util.TreeMap;
/**
* Allows to kill a certain Java process.
*/
public class JavaProcessKiller {
/**
* Kill a certain Java process. The JDK (jps) needs to be in the path.
*
* @param args the Java process name as listed by jps -l. If not set the
* Java processes are listed
*/
public static void main(String... args) {
new JavaProcessKiller().run(args);
}
private void run(String... args) {
TreeMap<Integer, String> map = getProcesses();
System.out.println("Processes:");
System.out.println(map);
if (args.length == 0) {
System.out.println("Kill a Java process");
System.out.println("Usage: java " + getClass().getName() + " <name>");
return;
}
String processName = args[0];
int killCount = 0;
for (Entry<Integer, String> e : map.entrySet()) {
String name = e.getValue();
if (name.equals(processName)) {
int pid = e.getKey();
System.out.println("Killing pid " + pid + "...");
// Windows
try {
exec("taskkill", "/pid", "" + pid, "/f");
} catch (Exception e2) {
// ignore
}
// Unix
try {
exec("kill", "-9", "" + pid);
} catch (Exception e2) {
// ignore
}
System.out.println("done.");
killCount++;
}
}
if (killCount == 0) {
System.out.println("Process " + processName + " not found");
}
map = getProcesses();
System.out.println("Processes now:");
System.out.println(map);
}
private static TreeMap<Integer, String> getProcesses() {
String processList = exec("jps", "-l");
String[] processes = processList.split("\n");
TreeMap<Integer, String> map = new TreeMap<Integer, String>();
for (int i = 0; i < processes.length; i++) {
String p = processes[i].trim();
int idx = p.indexOf(' ');
if (idx > 0) {
int pid = Integer.parseInt(p.substring(0, idx));
String n = p.substring(idx + 1);
map.put(pid, n);
}
}
return map;
}
private static String exec(String... args) {
ByteArrayOutputStream err = new ByteArrayOutputStream();
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
Process p = Runtime.getRuntime().exec(args);
copyInThread(p.getInputStream(), out);
copyInThread(p.getErrorStream(), err);
p.waitFor();
String e = new String(err.toByteArray(), "UTF-8");
if (e.length() > 0) {
throw new RuntimeException(e);
}
String output = new String(out.toByteArray(), "UTF-8");
return output;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
private static void copyInThread(final InputStream in, final OutputStream out) {
new Thread("Profiler stream copy") {
@Override
public void run() {
byte[] buffer = new byte[4096];
try {
while (true) {
int len = in.read(buffer, 0, buffer.length);
if (len < 0) {
break;
}
out.write(buffer, 0, len);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}.run();
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论