You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by cw...@apache.org on 2009/09/01 18:45:13 UTC
svn commit: r810116 -
/incubator/uima/uima-as/trunk/uimaj-as-jms/src/main/java/org/apache/uima/adapter/jms/client/BaseUIMAAsynchronousEngineCommon_impl.java
Author: cwiklik
Date: Tue Sep 1 16:45:13 2009
New Revision: 810116
URL: http://svn.apache.org/viewvc?rev=810116&view=rev
Log:
UIMA-1540 Modified to remove wait() from getCas(). Instead use the semaphore to signal availability of a CAS. There is no busy loop in this implementation.
Modified:
incubator/uima/uima-as/trunk/uimaj-as-jms/src/main/java/org/apache/uima/adapter/jms/client/BaseUIMAAsynchronousEngineCommon_impl.java
Modified: incubator/uima/uima-as/trunk/uimaj-as-jms/src/main/java/org/apache/uima/adapter/jms/client/BaseUIMAAsynchronousEngineCommon_impl.java
URL: http://svn.apache.org/viewvc/incubator/uima/uima-as/trunk/uimaj-as-jms/src/main/java/org/apache/uima/adapter/jms/client/BaseUIMAAsynchronousEngineCommon_impl.java?rev=810116&r1=810115&r2=810116&view=diff
==============================================================================
--- incubator/uima/uima-as/trunk/uimaj-as-jms/src/main/java/org/apache/uima/adapter/jms/client/BaseUIMAAsynchronousEngineCommon_impl.java (original)
+++ incubator/uima/uima-as/trunk/uimaj-as-jms/src/main/java/org/apache/uima/adapter/jms/client/BaseUIMAAsynchronousEngineCommon_impl.java Tue Sep 1 16:45:13 2009
@@ -488,11 +488,10 @@
}
if ( running ) { // only if the client is still running handle the new cas
try {
- entry.getSemaphore().acquire();
- // Associate the CAS with the entry and wake up the Consumer thread
+ // Associate the CAS with the entry and release the semaphore
entry.setCas(cas);
} finally {
- entry.getSemaphore().release();
+ entry.getSemaphore().release();
}
} else {
return; // Client is terminating
@@ -531,33 +530,17 @@
CasQueueEntry entry = getQueueEntry( Thread.currentThread().getId());
// Add this thread entry to the queue of threads waiting for a CAS
threadQueue.add(entry);
- // Create an object that we can use to wait before testing
- // availability of a CAS
- Object localWaitMonitor = new Object();
if ( entry != null ) {
while (running) {
- try {
- // Wait until the CAS producer adds the CAS to the CasQueueEntry and
- // signals CAS availability.
- entry.getSemaphore().acquire();
- if (entry.getCas() == null) {
- try {
- // A CAS may not be available for awhile. Allow CPUs to do other
- // work while we wait here for 100 millis before testing CAS
- // availability again.
- synchronized(localWaitMonitor) {
- localWaitMonitor.wait(100);
- }
- } catch( InterruptedException ex) {
-
- }
- continue;
- } else {
- return entry.getCas();
- }
- } finally {
- entry.getSemaphore().release();
- }
+ // Wait until the CAS producer thread adds a CAS to the CasQueueEntry and
+ // releases the semaphore.
+ entry.getSemaphore().acquire();
+ if (entry.getCas() == null) {
+ // Should not happen unless we are terminating
+ break;
+ } else {
+ return entry.getCas();
+ }
} // while
}
return null; // client has terminated
@@ -567,9 +550,6 @@
CasQueueEntry entry = null;
if ( threadRegistrar.containsKey(aThreadId ) ) {
entry = threadRegistrar.get(aThreadId);
- if ( entry != null ) {
- entry.reset();
- }
} else {
entry = new CasQueueEntry(new Semaphore(1));
threadRegistrar.put(aThreadId, entry);
@@ -595,9 +575,6 @@
public Semaphore getSemaphore() {
return semaphore;
}
- public void reset() {
- cas = null;
- }
}