Showing posts with label concurrency. Show all posts
Showing posts with label concurrency. Show all posts

Wednesday, 13 October 2010

Multi-threading with JMock

A way to make jmock 'pause' when running a test:

http://www.jmock.org/threading-scheduler.html


DeterministicScheduler scheduler = new DeterministicScheduler();
scheduler.tick(500, TimeUnit.MILLISECONDS);

Friday, 30 April 2010

ConcurrentSet

Assumping you dont want to use CopyOnWriteArraySet,

Create a ConcurrentHashMap (faster than the above because of its striped locking) and create a set from it.

http://java.sun.com/javase/6/docs/api/java/util/Collections.html#newSetFromMap%28java.util.Map%29


public static <E> Set<E> newSetFromMap(Map<E,Boolean> map)

Friday, 15 January 2010

Volatile vs Atomic

Volatile can gaurantee execution order and solve double checked logging problem.

You can not use Volatile as a counter shared by multiple threads. For that you must use Atomic

see:

http://jeremymanson.blogspot.com/2007/08/volatile-does-not-mean-atomic.html