java中多任务的任务调度?
我已经使用定时器构建了一个java时钟,它对于单个任务在下一个给定/设置的时间发出警报效果很好,但是我在使用这个计时器调度多个任务(不同时间的警报)时遇到问题,因为两次可以相互冲突(两个不同作品的时间相同)如何在这种情况下同步,请帮忙......
谢谢并问候
Alok Sharma
i have build a java clock with using timer,which works fine for a single task to alarm on next given/setted time, but i am having problem in scheduling multiple tasks(alarms for diff. times) with this timer, as two times can clash each other(same times for two different works) how to synchronize between such conditions, please help....
Thanks and Regards
Alok Sharma
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定你想做什么,但如果你使用quartz调度程序,你可以解决任何调度/同步任务:
http://www.quartz-scheduler.org/
I'm not sure what you're trying to do, but if you use quartz scheduler, you can resolve just about any scheduling/synchronisation task:
http://www.quartz-scheduler.org/
我同意卢卡斯的观点,你可以使用石英。它是最好的、可扩展的、强大的解决方案。
但如果您需要相对较小的东西,您可以继续使用基于计时器的解决方案。正如 Timer 类的 javadoc 所示,您的任务应该花费很少的时间。在这种情况下,您可以忘记时间冲突。如果您的任务花费超过 0.1 秒,请在单独的线程中运行它们。我的意思是使用计时器作为触发器,使任务在单独的线程中启动。
线程可以按如下方式完成:
在 J2EE 容器中使用 Timer itef 也是一种不好的做法。如果您在那里并且希望“干净”,请使用 JCA 来运行计时器。
I agree with Lukas that you can use quartz. It is the best, scalable and robust solution.
But if you need something relatively small you can continue using timer based solution. As javadoc of Timer class indicates your tasks should take very few time. In this case you can forget about time clash. If your tasks take more then 0.1 seconds run them in separate thread. I mean use Timer as a trigger that just makes task to start in separate thread.
The thread may be done as following:
Using Timer itsef in J2EE container is a bad practice too. If you are there and wish to be "clean" use JCA to to run Timer.