Skip to content

Month: September 2015

parallel counting in Java using AtomicInteger

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.TimeUnit;

class ParallelCounterExample {
   public static void main(String[] args) throws InterruptedException {
      int threads = 2000;
      ExecutorService executor = Executors.newFixedThreadPool(threads);
      final AtomicInteger atomi = new AtomicInteger();
      for(int i=0; i<threads; i++) {
         executor.execute( new Runnable() {
            @Override
            public void run() {
               atomi.getAndIncrement();
            }
         });
      }
      executor.awaitTermination(1, TimeUnit.SECONDS);
      executor.shutdown();
      System.out.println(atomi.get());
    }
}

Some of the photos from the supermoon total lunar eclipse yesterday. The next will be on November 25, 2034.
🌞🌎🌛
#moon #supermoon #bloodmoon #lunareclipse #perigee-syzygy #perigee #bloodmooneclipse #lua #penumbra #umbra #RayleighScattering.
Instagram: http://ift.tt/1FDqVtl

#supermoon #moon #eclipse #virginia #usa 🌞🌎🌙.
Instagram: http://ift.tt/1KEvL8G