简体   繁体   English

替代计划的任务,将来可能会取消

[英]Alternate to scheduled a task which may be canceled in future

In our server, We have provided one feature to send request to another server on specific time. 在我们的服务器中,我们提供了一种功能,可以在特定时间将请求发送到另一台服务器。

The scenario is as follow: 场景如下:

  • Server1 is send request for Session1 to our server Server1正在将对Session1的请求发送到我们的服务器

  • Request contains a time on which we have to send request to Server1 with same session-ID 请求包含一个时间,我们必须在该时间将请求发送到具有相同会话ID的Server1

We have achieve this by scheduling request on specific time. 我们通过在特定时间安排请求来实现此目的。

Ex. 防爆。

Session1 request received from Server1 on 10:00 AM and time given is 11:00 PM, so we scheduled that request for 11:00 PM. 从Server1在10:00 AM收到Session1请求,给定时间为11:00 PM,因此我们将该请求排定为11:00 PM。

The only problem is session may be terminated before time and we have to cancel the scheduled task for that session. 唯一的问题是会话可能会在时间之前终止,我们必须取消该会话的计划任务。

The ratio of session expired before given time is 10:8 ie 8 out of 10 will terminated before time. 在给定时间之前,会话终止的比例为10:8,即十分之八将在时间之前终止。

Java ScheduleThreadPool will only mark tha task to cancel when cancel on task will be called but does not remove the task. Java ScheduleThreadPool仅在调用取消任务而不删除任务时才将任务标记为取消。

I can not call Queue.purge() method to remove canceled task because the number of canceled task may be in lac ex. 我无法调用Queue.purge()方法来删除已取消的任务,因为已取消任务的数量可能在lac ex中。 2 lac 2紫胶

other solution is, 其他解决方案是

I can manage Map of <Session-ID, Time> , and on hourly basis I will check tha number of session-ID which will need to authenticate in next hour and scheduled only that session-id. 我可以管理<Session-ID, Time> Map,并按小时检查将在下一个小时进行身份验证的Session-ID的数量,并仅计划该Session-ID。 It will reduce some overhead because I will remove session-ID from map if it will terminated before time. 这将减少一些开销,因为如果它将在时间之前终止,我将从地图中删除会话ID。

please suggenst any other soution better than these or any changes in existing to optimize the above solution 请建议比这些建议更好的建议,或者建议对现有建议进行任何更改以优化上述解决方案

如果您可以使用ScheduledThreadPoolExecutor :默认情况下,API中有一个选项可让您删除已取消的任务: http ://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ScheduledThreadPoolExecutor 。 HTML#setRemoveOnCancelPolicy(布尔)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM