happyboy1024 commented on issue #5658:
URL: https://github.com/apache/seatunnel/issues/5658#issuecomment-1769845332

   The following code example simulates this concurrency problem:
   
   ```
   public static void main(String[] args) {
           while (true) {
               try {
                   Map<Integer, ArrayList<Integer>> map = new HashMap<>(2);
                   CountDownLatch countDownLatch = new CountDownLatch(2);
                   AtomicBoolean flag = new AtomicBoolean(true);
                   Thread reader1SplitThread = new Thread(() -> {
                       int readerIndex = 0;
                       try {
                           for (int i = 0; i < 100000; i++) {
                               map.computeIfAbsent(readerIndex, r -> new 
ArrayList<>()).add(i);
                           }
                       } catch (Exception e) {
                           flag.set(false);
                       }
                       countDownLatch.countDown();
                   });
                   Thread reader2SplitThread = new Thread(() -> {
                       int readerIndex = 1;
                       try {
                           for (int i = 0; i < 100000; i++) {
                               map.computeIfAbsent(readerIndex, r -> new 
ArrayList<>()).add(i);
                           }
                       } catch (Exception e) {
                           flag.set(false);
                       }
                       countDownLatch.countDown();
                   });
                   reader1SplitThread.start();
                   reader2SplitThread.start();
                   countDownLatch.await();
                   if (flag.get() && map.get(0).size() != map.get(1).size()) {
                       System.out.printf("assigned %s splits to reader 0%n", 
map.get(0).size());
                       System.out.printf("assigned %s splits to reader 1%n", 
map.get(1).size());
                       break;
                   }
               } catch (Exception ignored) {
   
               }
           }
   ```
   
   The results are as follows:
   
   
![image](https://github.com/apache/seatunnel/assets/137260654/1f4a7cbc-e1e5-4e13-82dd-0cba84d37eb6)
   
   The corresponding codes in seatunnel are as follows:
   
   
![image](https://github.com/apache/seatunnel/assets/137260654/abb724d0-bf79-43ed-b3ec-fc1a013478ca)
   
   


-- 
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]

Reply via email to