gpt4 book ai didi

java - Spring/JAVA连续进程同步

转载 作者:行者123 更新时间:2023-11-30 11:37:59 25 4
gpt4 key购买 nike

我有四个不同的进程(不同的方法),它们分别运行并计划在不同的时间启动。此进程也可以手动启动,并且必须一次运行一个。有没有处理这种并发的队列实现?我试图避免同一个进程在队列中两次,或者两个进程同时运行。

最佳答案

您似乎在寻找 Executors.newSingleThreadScheduledExecutor() :

Creates a single-threaded executor that can schedule commands to run after a given delay, or to execute periodically. (Note however that if this single thread terminates due to a failure during execution prior to shutdown, a new one will take its place if needed to execute subsequent tasks.) Tasks are guaranteed to execute sequentially, and no more than one task will be active at any given time.

关于java - Spring/JAVA连续进程同步,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13808703/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com