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

能否优化Future的 AbstractFuture#awaitDone(boolean timed, long nanos) 的性能 #44

Closed
Coneboy-k opened this issue Jan 15, 2018 · 1 comment

Comments

@Coneboy-k
Copy link

Coneboy-k commented Jan 15, 2018

在await时,能否添加自旋,减少waiter的上线文切换 ?

  nanos = deadline - System.nanoTime();
    if (nanos <= 0L) { // 设置超时, 阻塞当前线程(阻塞指定时间)
        removeWaiter(q);
        return state;
    }
   LockSupport.parkNanos(this, nanos);

如果等待时间过短,比如小于1000ns ,那么上下文的切换没有必要。此处请参考Guava 23 的实现。
com.google.common.util.concurrent.AbstractFuture#get(long, java.util.concurrent.TimeUnit)
另外 System.nanoTime() 有可能返回0

@Coneboy-k
Copy link
Author

;-)

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

No branches or pull requests

1 participant