Java:addScheduledJobAfterDelay() - 我可以强制启动计划作业吗?
我正在开发一款扑克游戏。在投注阶段,我使用 Red5 iSchedulingService 创建一个计划作业,该作业每 8 秒运行一次,转发给下一个玩家进行投注。现在,如果用户在 8 秒结束之前下注,我想手动强制启动下一个计划作业。
有没有办法强制预定的作业在需要时立即开始?
I'm developing a poker game. On the betting stage I create a scheduled job using Red5 iSchedulingService that will run every 8 seconds to forward to the next player to place a bet. Now if the user placed a bet before the 8 seconds are over, I want to manually force the next scheduled job to start.
Is there a way to force the scheduled job to start immediately when required?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 执行器。有更干净的实现,但这是一个尝试和一些基本的东西,可以使用 未来 和 可调用。
You can do this with Executors. There are cleaner implementations, but this is a stab and something basic that does what you want using Future and Callable.
我在这个线程中开始的具体问题的答案:
我不能强制启动计划作业,但我可以做的是删除计划作业并延迟 0 秒启动新作业。
addScheduledJobAfterDelay() 返回一个表示作业 ID 的字符串。我可以用它来删除预定的作业。问题是没有办法知道我是否中断了预定的工作。执行者确实提供了这些信息。这就是为什么在这种特定情况下执行器是比使用 red5 调度服务更好的选择。
如何删除计划作业 (red5):
字符串
ScheduleJobString
应替换为您在创建作业时收到的字符串:an answer to my specific question that I started with in this thread:
i cannot force to start a scheduled job, but what I can do is remove the scheduled job and start a new job with a delay of 0 seconds.
addScheduledJobAfterDelay() return a string that represents the job id. i can use it to remove the scheduled job. The problem is that there is no way to know if I'm interrupting the scheduled job or not. Executors do provide that information. that is why Executors are better choice in this specific case then using the red5 scheduling service.
how to remove a scheduled job (red5):
the string
ScheduleJobString
should be replaced with the string that you have received from creating the job: