You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2020/01/14 13:17:13 UTC

[GitHub] [incubator-iotdb] jt2594838 edited a comment on issue #738: [IOTDB-396] New query clause: disable align

jt2594838 edited a comment on issue #738: [IOTDB-396] New query clause: disable align
URL: https://github.com/apache/incubator-iotdb/pull/738#issuecomment-574168364
 
 
   CodeA does not encounter any concurrent correctness problem while CodeB does, so it is reasonable to believe the usage of primitives is safe.
   CodeA:
   ```
   public static void main(String[] args) throws InterruptedException {
       int[] ints = new int[100];
       ExecutorService executorService = Executors.newFixedThreadPool(10);
       for (int i = 0; i < 100; i++) {
         executorService.submit(new TestRunnable(i, executorService, ints));
       }
       Thread.sleep(10000);
       executorService.shutdownNow();
       for (int anInt : ints) {
         System.out.println(anInt);
       }
     }
   
     static class TestRunnable implements Runnable {
   
       int i;
       volatile int remain = 100;
       ExecutorService service;
       int[] ints;
   
       public TestRunnable(int i, ExecutorService service, int[] ints) {
         this.i = i;
         this.service = service;
         this.ints = ints;
       }
   
       @Override
       public void run() {
         ints[i] ++;
         remain --;
         if (remain > 0) {
           service.submit(this);
         }
       }
     }
   ```
   
   CodeB:
   ```
   public static void main(String[] args) throws InterruptedException {
       int[] ints = new int[100];
       ExecutorService executorService = Executors.newFixedThreadPool(10);
       for (int i = 0; i < 100; i++) {
         executorService.submit(new TestRunnable(i, executorService, ints));
       }
       Thread.sleep(10000);
       executorService.shutdownNow();
       for (int anInt : ints) {
         System.out.println(anInt);
       }
     }
   
     static class TestRunnable implements Runnable {
   
       int i;
       volatile int remain = 100;
       ExecutorService service;
       int[] ints;
   
       public TestRunnable(int i, ExecutorService service, int[] ints) {
         this.i = i;
         this.service = service;
         this.ints = ints;
       }
   
       @Override
       public void run() {
         ints[0] ++;
         remain --;
         if (remain > 0) {
           service.submit(this);
         }
       }
     }
   ```

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services