java schedule a callable at pseudo 'fixed' rate (bell curve distribution for example)

你说的曾经没有我的故事 提交于 2019-12-01 09:57:52

问题


Currently I have a ScheduledThreadPoolExecutor which can execute a callable at a fixed rate.

scheduledThreadPoolExecutor.scheduleAtFixedRate(callable, delay, waitNano, TimeUnit.NANOSECONDS);

My team wants to add some randomess into the waitNano. Currently it is 1000. But we want the wait second to be 900, 1100, 800, 1200, for example. The average wait time is still 1000 but the wait second is randomly distributed, (for example like a Bell curve).

I am wondering is this functionality already in java? If I have to write my own "scheduler" which has this random-waiting behavior, what do you guys suggest?

Thanks a lot!

Erben


回答1:


Invoke another Runnable at fixed schedules (for example 10 min) and let it configure random scheduler's next execution randomly still managing randomness

using schedule();

For example: first column shows execution of fixed scheduler which determines when to execute managed random scheduler

0    1
5    7
10   11
15   18


来源:https://stackoverflow.com/questions/22794010/java-schedule-a-callable-at-pseudo-fixed-rate-bell-curve-distribution-for-exa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!