public static void main(String args[]){
        ExecutorService executor = Executors.newFixedThreadPool(10);
        RealTimeCounter realTimeCounter = new RealTimeCounter();
        final Random random = new Random();
        final int TOTAL_EVENTS = 10000;
        CountDownLatch countDownLatch = new CountDownLatch(TOTAL_EVENTS);
        for(int i=0; i < TOTAL_EVENTS; i++){
            executor.execute(() -> {
                realTimeCounter.addEvent();
                try {
                    Thread.sleep(random.nextInt(10));
                } catch (Exception e) {
                    e.printStackTrace();
                }
                countDownLatch.countDown();
            }
            );
        }
        try{
            countDownLatch.await();
        }catch(Exception e){
            
        }
        System.out.println(realTimeCounter.getTotalEvents());
        executor.shutdownNow();
    }
Date 03/03/2015
@author tusroy

Develop a software to count number of events in last 5 mins. You have to support two apis
1) addEvent() -> It means increment event by 1
2) getTotalEvents() -> Return total number of events in last 5 mins

Program should support millions of events every minute and should also provide multi-threading support

This class might not have 100% accuracy as far as events in last 5 mins are concerned. 
Since we are using circular queue last second information may not be very accurate.

Solution:
Keep atomiclong of 300 in array. PositionUpdater updates position every second.
@Threadsafe
src/com/interview/multithreaded/RealTimeCounter.java