且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

具有计时器的可执行jar

更新时间:2023-09-29 22:06:52

定时精度 所示时钟分辨率取决于主机平台和操作系统。虽然 javax.swing.Timer 将默认合并事件,定时器线程将在这么短的时间(高频率)下快速饱和。您可能需要在旧系统上进行补偿。


I wrote a program with two timers running small animations. Originally timerX was running at 5ms and timerY was running a 1ms. I exported the program to an executable jar file and everything worked fine. I then sent the jar to another computer running the same specs and again there were no problems. However, I decided to speed up timerX, so I changed this timer to run at 1ms, ran, saved and exported the file. From my desktop this new file ran perfectly but when passing it to the other computer there was no change from the previous one. Is there something I need to do in eclipse before I resend it to the executable jar file? Also why is it running fine from my desktop but not on the other computer - the second timer which is also set at 1ms runs equally fast in both instances.

As shown in Timer accuracy, clock resolution depends on the host platform and operating system. Although javax.swing.Timer will coalesce events by default, the timer thread will tend to saturate quickly with such a short period (high frequency). You may need to compensate on older systems.