@Test
	public void multiThreadedTest() throws InterruptedException {

		final AtomicBoolean failed = new AtomicBoolean(false);
		final AvgCounter c = new AvgCounter();
		final AtomicLong index = new AtomicLong(0);
		ArrayList<Thread> threads = new ArrayList<Thread>();

		for (int i = 0; i < 10; i++) {
			Thread t = new Thread(new Runnable() {
				public void run() {
					try {
						long currentIndex = index.incrementAndGet();
						while (currentIndex < 40000000) {
							c.addValue(currentIndex);

							if (currentIndex % 10000 == 0)
								c.getValue();

							currentIndex = index.incrementAndGet();
						}
					}
					catch (Exception e) {
						failed.set(true);
					}
				}
			});

			threads.add(t);
			t.setDaemon(true);
		}

		for (Thread t : threads) {
			t.start();
		}

		for (Thread t : threads) {
			t.join();
		}

		if (failed.get())
			Assert.fail();
	}