小编T. *_*cis的帖子

“长时间监视器争用事件”有什么问题

我有以下服务代码,我在其中启动了一个线程,负责在消息传入时分派消息。

       public void run() {
          while (! Thread.interrupted()) {
            try {
              Message msg = null;
              synchronized (_queue) {
                if (_queue.size() == 0) {
                  _queue.wait(10000);
                }

                if (_queue.size() != 0) {
                  msg = _queue.poll();
                }

                if (msg != null) {
                  _dispatcher.dispatch(msg);
                }
              }
            }
            catch (InterruptedException i) {                }
            catch (Exception e) {                }
          }
      }
  public void add (final Message m){
    if (m == null)
      return;
    synchronized (_queue){
      _queue.add(m);
      _queue.notify();
    }
  }
Run Code Online (Sandbox Code Playgroud)

但是当这段代码在我的 android 模拟器上运行时,我收到了很多如下警告:

Long monitor contention event with …
Run Code Online (Sandbox Code Playgroud)

android java-threads

5
推荐指数
1
解决办法
4726
查看次数

标签 统计

android ×1

java-threads ×1