chronos icon indicating copy to clipboard operation
chronos copied to clipboard

异步同步数据,为什么每次都创建新线程

Open fuyou001 opened this issue 11 years ago • 3 comments

异步同步数据数据,每次新创建线程不是性能瓶颈点。 即使这样,用线程池是否更好些呢?

 public synchronized void asyncSetPersistentTimestamp(final long newPersistentTimestamp) {
    new Thread() {
      @Override
      public void run() {
        try {
          chronosServerWatcher.setPersistentTimestamp(newPersistentTimestamp);
          isAsyncSetPersistentTimestamp = false;
        } catch (Exception e) {
          LOG.fatal("Error to set persistent timestamp, exit immediately");
          System.exit(0);
        }
      }
    }.start();
  }

fuyou001 avatar Apr 23 '14 14:04 fuyou001

很有价值的issue,设计之初没有考虑到,谢谢提醒。

tobegit3hub avatar Apr 24 '14 02:04 tobegit3hub

既然是异步,asyncSetPersistentTimestamp方法上加synchronized又有什么用呢? 同步方法,里面又弄新线程,感觉很矛盾

chengnl avatar Apr 28 '14 10:04 chengnl

@chengnl asyncSetPersistentTimestamp加synchronized是为了避免同时被调用到,同步方法里new新线程就是为了执行异步操作。这部分有点绕,会整理好的。

tobegit3hub avatar May 04 '14 08:05 tobegit3hub