Skip to content

Instantly share code, notes, and snippets.

@hgdeoro
Created August 2, 2011 12:35
Show Gist options
  • Save hgdeoro/1120097 to your computer and use it in GitHub Desktop.
Save hgdeoro/1120097 to your computer and use it in GitHub Desktop.
Simple java class to crash the JVM (works with Sun/Oracle JVM)
import java.io.IOException;
import java.net.ServerSocket;
import sun.dc.pr.PathDasher;
public class JvmCrasher {
public static void log(String msg) {
try {
Runtime.getRuntime().exec(new String[] { "/usr/bin/logger", "-t", "TestCaidaJvm", msg }).waitFor();
} catch (InterruptedException e) {
} catch (IOException e) {
}
}
public static void main(String[] args) throws IOException {
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
log("shutdownHook(): Iniciando...");
try {
for (int i = 10; i >= 1; i--) {
log("shutdownHook(): " + i + " segs. para finalizar");
Thread.sleep(1000);
}
} catch (InterruptedException e) {
log("shutdownHook(): InterruptedException");
}
log("shutdownHook(): FIN!");
}
});
ServerSocket socket = new ServerSocket(0);
log("Esperando conexion en puerto " + socket.getLocalPort() + " para generar crash");
socket.accept();
log("Se generara crash");
PathDasher dasher = new PathDasher(null);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment