如何在收到SIGINT时实现SpringBoot应用程序内java ffmpeg进程的优雅关闭?

发布于 2025-01-09 19:38:11 字数 1364 浏览 1 评论 0原文

我目前正在开发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时,

  1. ffmpeg被杀死并带有255状态代码(SIGINIT)
  2. 句柄方法被执行

有没有办法等待一定的时间那些正在运行的 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

  1. ffmpeg gets killed of with 255 status code ( SIGINIT)
  2. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文