java - jconsole.exe 防止了 JVM 崩溃
问题描述
我目前正在使用 amazone corretto 8、嵌入式 SQLite DB 和 Sarxos 使用 Maven 开发的 WebCam Capture API 开发 JavaFX 应用程序。应用程序本身运行平稳,满载时需要大约 1.2 GB 的 RAM。
不幸的是,当使用视频流的执行器服务重复加载和终止线程时,我的 JDK 崩溃了。但是,当我尝试使用 jconsole 进行根本原因分析时,崩溃是不可重现的。
知道如何确定崩溃的根本原因,或者 jconsole 如何防止崩溃?很难重现大量内存,但这里是视频流的代码:
/* Method to initialize WebCam
* by:
* Closing open WebCam
* Opening WebCam based on Index position
* Referring to method to start WebCam feed/stream to ImageView
*/
public static void initializeWebCam(final int webCamIndex) {
executorService = createFixedTimeoutExecutorService(2, 3000, TimeUnit.MILLISECONDS);
Task<Void> iniWebCamTask = new Task<Void>() {
@Override
protected Void call() throws Exception {
if (webCam != null) {disposeWebCamCamera();}
webCam = Webcam.getWebcams().get(webCamIndex);
webCam.open();
startWebCamStreamTask();
//stop Camera if WebCam is no longer in scene
webCamPane.sceneProperty().addListener((obs, oldScene, newScene) -> {
if (newScene == null) {
disposeWebCamCamera();
executorService.shutdownNow();
mbc.ewatson.App.log.info("Shutting down camera streaming thread");
}
});
return null;
}
};
/*
* method which starts the WebCam stream
* by:
* creating a updated/atomic Reference which
* sets image to null and flushing buffer/ cache
* updated image from if loop
*/
protected static void startWebCamStreamTask() {
stopCamera = false;
Task<Void> streamImageTask = new Task<Void>() {
@Override
protected Void call() throws Exception {
final AtomicReference<WritableImage> ref = new AtomicReference<>();
BufferedImage img = null;
while (!stopCamera) {
try {
if ((img = webCam.getImage()) != null) {
ref.set(SwingFXUtils.toFXImage(img, ref.get()));
img.flush();
//JavaFX thread
Platform.runLater(new Runnable() {
@Override
public void run() {
imageProperty.set(ref.get());
}
});
}
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
};
/*Creates an executor service with a fixed pool size, that will time
* out after a certain period of inactivity.
*
* @param poolSize The core- and maximum pool size
* @param keepAliveTime The keep alive time
* @param timeUnit The time unit
* @return The executor service
*/
public static ExecutorService createFixedTimeoutExecutorService(int poolSize, long keepAliveTime, TimeUnit timeUnit){
ThreadPoolExecutor e =
new ThreadPoolExecutor(poolSize, poolSize,
keepAliveTime, timeUnit, new LinkedBlockingQueue<Runnable>());
e.allowCoreThreadTimeOut(true);
return e;
}
这是错误日志:
2020 年 7 月 20 日 2:15:27 NACHM。..view.trialpoints.edit.ErprobungspunkteRightFileInput$createFileInputObjects lambda$startWebCamStreamTask$4 信息:正在运行相机 [错误] 命令执行失败。org.apache.commons.exec.ExecuteException:进程退出并出现错误:-1073740940(退出值:-1073740940)在 org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:404)在 org.apache.commons .exec.DefaultExecutor.execute(DefaultExecutor.java:166) 在 org.openjfx.JavaFXBaseMojo.executeCommandLine(JavaFXBaseMojo.java:504) 在 org.openjfx.JavaFXBaseMojo.executeCommandLine(JavaFXBaseMojo.java:394) 在 org.openjfx.JavaFXRunMojo。在 org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:
解决方案
推荐阅读
- rest - Flutter 从服务器获取日语字符解码错误
- sql-server - SQL Server 导入向导和临时表
- roots-sage - 您如何部署(使用 Roots Trellis)到有 CloudFlare 代理的域?
- android - 在 Android 中将字符串数组发送到本机代码
- c# - 使用 lambda 表达式在实体框架 6 中进行 SQL 字宽“%like%”搜索
- r - R为什么do.call不匹配直接计算?
- dart - Flutter:Stream Builder 在使用 observable1.mergeWith([observable2]) 时无法正常工作
- tensorflow - 自制嵌入可以用于 RNN,还是必须经过训练?
- spring-boot - @Id 未映射到 Spring-Boot 控制器中的特定实体
- r - 数据框所有列的 Anderson-Darling 正态性检验