caiconghui commented on PR #11422:
URL: https://github.com/apache/doris/pull/11422#issuecomment-1202025186

   ```
    Map<Long, Long> map = new HashMap<>();
           StampedLock lock = new StampedLock();
           ForkJoinPool pool = new ForkJoinPool(10);
           long size = 1000000;
           IntStream range = IntStream.range(0, (int) size);
           long[] valueList = new long[(int)size];
           long startTime = System.currentTimeMillis();
           Thread writer = new Thread(new Runnable() {
               @Override
               public void run() {
                   Random random = new Random();
                   for (long i = 0; i < 100000; i++) {
                       long stamp = lock.writeLock();
                       try {
                           map.put(i, random.nextLong());
                       } finally {
                           lock.unlockWrite(stamp);
                       }
                   }
               }
           });
           writer.start();
   
           pool.submit(() -> range.parallel().forEach(
                   value -> {
                       long stamp = lock.readLock();
                       try {
                           Long v = map.get(value);
                           if (v != null) {
                               valueList[value] = v;
                           }
                       } finally {
                           lock.unlockRead(stamp);
                       }
                   }
           )).join();
           writer.join();
   
           long cost = System.currentTimeMillis() - startTime;
           System.out.println("time cost = " + cost);
   ```
   StampLock cost about 213ms while ReentrantReadWriteLock cost about 300ms


-- 
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: commits-unsubscr...@doris.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to