Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fuyou001 opened this issue Apr 23, 2014 · 3 comments
Open

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

fuyou001 opened this issue Apr 23, 2014 · 3 comments

Comments

@fuyou001
Copy link

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

 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();
  }

@tobegit3hub
Copy link
Contributor

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

@chengnl
Copy link

chengnl commented Apr 28, 2014

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

@tobegit3hub
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants