摆动速率限制
我有一个很长的重绘操作,我想对其进行速率限制,即确保它最多每 N 毫秒调用一次。
我当前的解决方案有些不尽如人意:我使用持续时间较短的 Swing Timer
,每当收到事件时我都会 restart()
。这可以确保如果事件在 N 毫秒窗口内发生,则不会触发重绘(即,重绘将在事件发生且经过 N 毫秒“安静”期后发生)。
我想要的是确保在第一个事件发生后最多 N 毫秒调用重绘,并且重绘周期最多为 N。有什么想法吗? (未记录在已启动的 Timer
上调用 start
的效果)。
I have a long repaint operation that I would like to rate-limit, ie make sure it gets called once every N milliseconds at most.
My current solution is somewhat unsatisfactory: I use a Swing Timer
with a short duration, which I restart()
whenever I get an event. This make sure that a repaint is not triggered if events happen within an N milliseconds window (i.e. the repaint will happen after an event and an N milliseconds "quiet" period has elapsed).
What I would like is to make sure the repaint is called at most N milliseconds after the first event and that the repaint period is at most N. Any ideas? (the effect of calling start
on an already-started Timer
is not documented).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,只有来自本机操作系统的延迟,如果您将溢出此刷新率,则来自 RepaintManager 的错误,顺便说一句,您的主题非常学术
延迟是每秒一个像素的最大刷新率
,但是 这个
或另一个应该是测试的良好基础,直到来自 RepaintManager 的第一个错误(然后可能锁定当前 JVM 实例)
来自代码
there as are I know only Latency that came from Native OS, if you will overflow this refresh rate then comes Error(s) from RepaintManager, btw your topic is very academic
Latency is maximum refresh rate for one pixel / per seconds
but this one
or another should be good bases for testing untill / UpTo first Error(s) comings from RepaintManager (then probably lock current JVM instance)
from code