Hi guys,
I'm looking through the caching of composite method instances, and
noticed that if I use the pool that uses AtomicReferences instead of
"synchronized" to maintain the pool, the performance goes up by a nr of
million invocations per second. So, the main question is whether the
pool logic is correct. Here it is:
public final class AtomicInstancePool
implements InstancePool<CompositeMethodInstance>
{
private final AtomicReference<CompositeMethodInstance> first = new
AtomicReference<CompositeMethodInstance>();
public CompositeMethodInstance getInstance()
{
CompositeMethodInstance firstInstance;
do
{
firstInstance = first.get();
} while(firstInstance != null && !first.compareAndSet(
firstInstance, firstInstance.getNext() ));
return firstInstance;
}
public void returnInstance( CompositeMethodInstance
compositeMethodInstance )
{
CompositeMethodInstance previous = first.getAndSet(
compositeMethodInstance );
compositeMethodInstance.setNext( previous );
}
}
---
The main question is: is the getInstance/returnInstance methods
thread-safe or not? If I understand the AtomicReference API correctly, I
think it is. Can you see any way that this could get screwed up?
/Rickard
_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev