A scheduled task will invoke 3rd party library and sometimes JVM crashes and it cannot be recovered.
Solution:
Use ProcessBuilder to invoke the possible-crash application. (It works on JRE7, not on JRE6)
public
class CrashExample {
System.
out.println("Hello, I will crash!");
}
}
import
java.io.IOException;
import
java.util.concurrent.Executors;
import
java.util.concurrent.TimeUnit;
public
class FixedTest {
Executors.newScheduledThreadPool(10).scheduleAtFixedRate(
new Runnable() {
System.
out.println("Running..."+cnt);
}
String separator = System.getProperty(
"file.separator");
String classpath = System.getProperty(
"java.class.path");
String path = System.getProperty(
"java.home")
+ separator +
"bin" + separator + "java";
System.
out.println("path="+path);
ProcessBuilder processBuilder =
classpath,
CrashExample.
class.getName());
// processBuilder.inheritIO();
Process process = processBuilder.start();
process.waitFor();
}
catch (IOException e) {
e.printStackTrace();
}
catch (InterruptedException e) {
e.printStackTrace();
}
System.
out.println("Running "+cnt);
}
}
}, 100, 1000, TimeUnit.
MILLISECONDS);
}
}
Good information. World-class thread dump analyzer to fire fight any sort of JVM related availability, scalability and performance problems. Applies several intelligence patterns discovers the root cause of the problem instantly.Java Thread Dump Analyzer
ReplyDelete