More efficient way for pausing loop wanted

后端 未结 4 1249
后悔当初
后悔当初 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:28

    I believe the best way here would be to use Thread.wait for the waiting thread instead of sleeping, and use Thread.notify in the thread you are waiting for. More info here: http://www.javamex.com/tutorials/synchronization_wait_notify.shtml

提交回复
热议问题