如何在收到SIGINT时实现SpringBoot应用程序内java ffmpeg进程的优雅关闭?
我目前正在开发SpringBoot 2.6版本。 3应用程序。应用程序在线程池执行器上运行ffmpeg进程,例如:
@Bean(name = "ffmpeg")
public TaskExecutor getAncaExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(10);
executor.setMaxPoolSize(10);
executor.setQueueCapacity(100);
executor.setThreadNamePrefix("ffmpeg-");
executor.setWaitForTasksToCompleteOnShutdown(true);
executor.setAwaitTerminationSeconds(120);
executor.initialize();
return executor;
}
@Autowired("ffmpeg")
TaskExecutor taskExecutor;
public void transcode() {
CompletableFuture.supplyAsync(() -> {
Process process = Runtime.getRuntime().exec("ffmpeg -i input -y.......");
result = process.waitFor();
return result;
}, taskExecutor).thenAccept(result -> handleResult());
});
}
在我的application.properties中,
server.shutdown=graceful
spring.lifecycle.timeout-per-shutdown-phase=120s
当应用程序收到SIGINIT时,
- ffmpeg被杀死并带有255状态代码(SIGINIT)
- 句柄方法被执行
有没有办法等待一定的时间那些正在运行的 ffmpeg 进程结束的时间,如果 taskExecutor 已经使用,为什么 Spring Boot 会杀死它们setWaitForTasksToCompleteOnShutdown(true);setAwaitTerminationSeconds(120);
I am currently developing a SpringBoot version 2.6. 3 application.The app runs ffmpeg processes on thread pool executors like:
@Bean(name = "ffmpeg")
public TaskExecutor getAncaExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(10);
executor.setMaxPoolSize(10);
executor.setQueueCapacity(100);
executor.setThreadNamePrefix("ffmpeg-");
executor.setWaitForTasksToCompleteOnShutdown(true);
executor.setAwaitTerminationSeconds(120);
executor.initialize();
return executor;
}
@Autowired("ffmpeg")
TaskExecutor taskExecutor;
public void transcode() {
CompletableFuture.supplyAsync(() -> {
Process process = Runtime.getRuntime().exec("ffmpeg -i input -y.......");
result = process.waitFor();
return result;
}, taskExecutor).thenAccept(result -> handleResult());
});
}
in my application.properties I have
server.shutdown=graceful
spring.lifecycle.timeout-per-shutdown-phase=120s
When the app receives SIGINIT
- ffmpeg gets killed of with 255 status code ( SIGINIT)
- handle method is executed
Is there a way to wait a certain amount of time on those running ffmpeg processes to end, why does Spring Boot kills them off if taskExecutor has been with setWaitForTasksToCompleteOnShutdown(true);setAwaitTerminationSeconds(120);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论