Author: borges
Date: 2011-10-21 10:24:50 -0400 (Fri, 21 Oct 2011)
New Revision: 11575
Modified:
branches/Branch_2_2_EAP/src/main/org/hornetq/core/remoting/impl/netty/NettyConnection.java
Log:
JBPAPP-7353 Use Semaphore instead of Lock.
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-21
14:14:30 UTC (rev 11574)
+++
branches/Branch_2_2_EAP/src/main/org/hornetq/core/remoting/impl/netty/NettyConnection.java 2011-10-21
14:24:50 UTC (rev 11575)
@@ -14,8 +14,7 @@
package org.hornetq.core.remoting.impl.netty;
import java.util.Set;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
+import java.util.concurrent.Semaphore;
import org.hornetq.api.core.HornetQBuffer;
import org.hornetq.api.core.HornetQBuffers;
@@ -61,7 +60,7 @@
private volatile HornetQBuffer batchBuffer;
- private final Lock writeLock = new ReentrantLock();
+ private final Semaphore writeLock = new Semaphore(1);
private Set<ReadyListener> readyListeners = new
ConcurrentHashSet<ReadyListener>();
@@ -153,7 +152,7 @@
return;
}
- if (writeLock.tryLock())
+ if (writeLock.tryAcquire())
{
try
{
@@ -166,7 +165,7 @@
}
finally
{
- writeLock.unlock();
+ writeLock.release();
}
}
}
@@ -179,7 +178,8 @@
public void write(HornetQBuffer buffer, final boolean flush, final boolean batched)
{
- writeLock.lock();
+ try {
+ writeLock.acquire();
try
{
@@ -240,9 +240,14 @@
}
}
}
- finally
+ finally
+ {
+ writeLock.release();
+ }
+ }
+ catch (InterruptedException e)
{
- writeLock.unlock();
+ Thread.currentThread().interrupt();
}
}
Show replies by date