简体   繁体   中英

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

  • Request contains a time on which we have to send request to Server1 with same session-ID

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.

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.

Java ScheduleThreadPool will only mark tha task to cancel when cancel on task will be called but does not remove the task.

I can not call Queue.purge() method to remove canceled task because the number of canceled task may be in lac ex. 2 lac

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. It will reduce some overhead because I will remove session-ID from map if it will terminated before time.

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(布尔)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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