You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by GitBox <gi...@apache.org> on 2021/12/16 12:44:54 UTC

[GitHub] [rocketmq] XiaoyiPeng removed a comment on pull request #3509: [ISSUE #2516]: Fix the value of sendThreadPoolQueueHeadWaitTimeMills is 0 most of the time

XiaoyiPeng removed a comment on pull request #3509:
URL: https://github.com/apache/rocketmq/pull/3509#issuecomment-995780683


   > Hi, @areyouok @RongtongJin @duhenglucky
   > 
   > I reviewed the given test cases again, the broker will never hangs in your test, @areyouok
   > 
   > In your test case, the reason you made the judgment: **broker hangs**, is due to your console println "begin scan, i still alive", but not println "finish scan, i still alive" finally, or vice versa.
   > 
   > **That's because the IDE console lied to us!** **Our naked eyes do not perceive the tiny change in the console !**
   > 
   > You can use `AtomicInteger` to print the times of prints before you print "begin scan, i still alive" and "finish scan, i still alive". The code shown below:
   > 
   > ```java
   > public class TestLinkedBlockingQueue {
   >     public static void main(String[] args) throws InterruptedException {
   >         AtomicInteger startScanTimes = new AtomicInteger();
   >         AtomicInteger finishScanTimes = new AtomicInteger();
   >         LinkedBlockingQueue<Object> queue = new LinkedBlockingQueue<>();
   >         for (int i = 0; i < 10; i++) {
   >             new Thread(() -> {
   >                 while (true) {
   >                     queue.offer(new Object());
   >                     queue.remove();
   >                 }
   >             }).start();
   >         }
   > 
   >         while (true) {
   >             System.out.println("begin scan, i still alive, times: " + startScanTimes.incrementAndGet());
   >             queue.stream().filter(o -> o != null)
   >                     .findFirst().isPresent();
   >             Thread.sleep(1000);
   >             System.out.println("finish scan, i still alive, times: " + finishScanTimes.incrementAndGet());
   >         }
   >     }
   > }
   > ```
   > 
   > **We can run a fatigue test with this test case, it will never hangs and print the given info forever!**
   > 
   > As for the **potential deadlock**, that was my initial misjudgment. In methods of class `LinkedBlockingQueue`, `putLock` and `takeLock` are never acquired simultaneously in a different order.
   > 
   > best regards!
   
   


-- 
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: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org