More efficient way for pausing loop wanted

后端 未结 4 1220
后悔当初
后悔当初 2020-11-27 22:03

Is it possible to rewrite this code for better working with processor? I have a class, which does some tasks with fixed periodicy in a separate thread. Sometimes this proces

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-27 22:49

    You can improve efficiency drastic by using a monitor instead of sleeping the thread. You just make blocks in your code with a keyword synchronized. And an final Object that's acts the monitor. Look uP more in the API on monitors.

提交回复
热议问题