Java Timer

后端 未结 3 752
萌比男神i
萌比男神i 2020-11-29 10:05

I\'m trying to use a timer to schedule a recurring event in an application. However, I want to be able to adjust the period at which the event fires in real time (according

3条回答
  •  爱一瞬间的悲伤
    2020-11-29 10:36

    It seems odd to me to have a TimerTask with its own Timer inside it. Bad design. I'd totally separate the two and have the TimerTask implementation be handed off to a Timer, and put all that logic about fiddling with the period inside another class that provides an interface for doing so. Let that class instantiate the Timer and TimerTask and send them off to do their work.

提交回复
热议问题