XiaoyiPeng commented on a change in pull request #3509:
URL: https://github.com/apache/rocketmq/pull/3509#discussion_r752836279
##########
File path: broker/src/main/java/org/apache/rocketmq/broker/BrokerController.java
##########
@@ -650,10 +652,13 @@ public void protectBroker() {
public long headSlowTimeMills(BlockingQueue<Runnable> q) {
long slowTimeMills = 0;
- final Runnable peek = q.peek();
- if (peek != null) {
- RequestTask rt = BrokerFastFailure.castRunnable(peek);
- slowTimeMills = rt == null ? 0 : this.messageStore.now() -
rt.getCreateTimestamp();
+ Optional<RequestTask> op = q.stream()
Review comment:
Thanks for your review.
It has nothing to do with thread safety, There is to reduce thread
contention, `q` is polled by thread in `BrokerController#sendMessageExecutor`
and will be peeked by thread in `BrokerController#scheduledExecutorService`
per second as shown below, both `poll()` and `peek()` method will grab the lock
`(LinkedBlockingQueue#takeLock)
`
```
this.scheduledExecutorService.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
try {
BrokerController.this.printWaterMark();
} catch (Throwable e) {
log.error("printWaterMark error.", e);
}
}
}, 10, 1, TimeUnit.SECONDS);
```
You can look at the issue #2516 , get some context info first.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]