Author: borges
Date: 2011-10-20 08:01:57 -0400 (Thu, 20 Oct 2011)
New Revision: 11569
Modified:
branches/Branch_2_2_EAP/src/main/org/hornetq/core/remoting/impl/netty/NettyConnection.java
Log:
JBPAPP-7353 Fixes[*] NettyMultiThreadRandomReattachTest hang (needs performance
evaluation)
[*] It fixes a otherwise reproducible hang in a Sun 32bit JVM.
Still need verification in the reported IBM JDK case.
Modified:
branches/Branch_2_2_EAP/src/main/org/hornetq/core/remoting/impl/netty/NettyConnection.java
===================================================================
---
branches/Branch_2_2_EAP/src/main/org/hornetq/core/remoting/impl/netty/NettyConnection.java 2011-10-20
12:01:42 UTC (rev 11568)
+++
branches/Branch_2_2_EAP/src/main/org/hornetq/core/remoting/impl/netty/NettyConnection.java 2011-10-20
12:01:57 UTC (rev 11569)
@@ -14,7 +14,8 @@
package org.hornetq.core.remoting.impl.netty;
import java.util.Set;
-import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
import org.hornetq.api.core.HornetQBuffer;
import org.hornetq.api.core.HornetQBuffers;
@@ -60,7 +61,7 @@
private volatile HornetQBuffer batchBuffer;
- private final AtomicBoolean writeLock = new AtomicBoolean(false);
+ private final Lock writeLock = new ReentrantLock();
private Set<ReadyListener> readyListeners = new
ConcurrentHashSet<ReadyListener>();
@@ -152,7 +153,7 @@
return;
}
- if (writeLock.compareAndSet(false, true))
+ if (writeLock.tryLock())
{
try
{
@@ -165,7 +166,7 @@
}
finally
{
- writeLock.set(false);
+ writeLock.unlock();
}
}
}
@@ -177,11 +178,9 @@
public void write(HornetQBuffer buffer, final boolean flush, final boolean batched)
{
- while (!writeLock.compareAndSet(false, true))
- {
- Thread.yield();
- }
+ writeLock.lock();
+
try
{
if (batchBuffer == null && batchingEnabled && batched &&
!flush)
@@ -243,7 +242,7 @@
}
finally
{
- writeLock.set(false);
+ writeLock.unlock();
}
}