[hornetq-commits] JBoss hornetq SVN: r12308 - in trunk/hornetq-core/src/main/java/org/hornetq: utils and 1 other directory.
do-not-reply at jboss.org
do-not-reply at jboss.org
Fri Mar 16 11:23:31 EDT 2012
Author: borges
Date: 2012-03-16 11:23:31 -0400 (Fri, 16 Mar 2012)
New Revision: 12308
Modified:
trunk/hornetq-core/src/main/java/org/hornetq/core/paging/cursor/impl/PageCursorProviderImpl.java
trunk/hornetq-core/src/main/java/org/hornetq/utils/Future.java
Log:
Avoid using Object.wait() and Object.notify()
Modified: trunk/hornetq-core/src/main/java/org/hornetq/core/paging/cursor/impl/PageCursorProviderImpl.java
===================================================================
--- trunk/hornetq-core/src/main/java/org/hornetq/core/paging/cursor/impl/PageCursorProviderImpl.java 2012-03-16 15:23:12 UTC (rev 12307)
+++ trunk/hornetq-core/src/main/java/org/hornetq/core/paging/cursor/impl/PageCursorProviderImpl.java 2012-03-16 15:23:31 UTC (rev 12308)
@@ -264,10 +264,8 @@
while (!future.await(10000))
{
- log.warn("Waiting cursor provider " + this + " to finish executors" + executor);
-
+ log.warn("Waiting cursor provider " + this + " to finish " + future + ", running on executor " + executor);
}
-
}
public void flushExecutors()
Modified: trunk/hornetq-core/src/main/java/org/hornetq/utils/Future.java
===================================================================
--- trunk/hornetq-core/src/main/java/org/hornetq/utils/Future.java 2012-03-16 15:23:12 UTC (rev 12307)
+++ trunk/hornetq-core/src/main/java/org/hornetq/utils/Future.java 2012-03-16 15:23:31 UTC (rev 12308)
@@ -12,47 +12,38 @@
*/
package org.hornetq.utils;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
/**
* A Future
- *
+ *
* @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
*
*/
public class Future implements Runnable
{
- private boolean done;
+ private final CountDownLatch latch = new CountDownLatch(1);
- public synchronized boolean await(final long timeout)
+ public boolean await(final long timeout)
{
- long toWait = timeout;
-
- long start = System.currentTimeMillis();
-
- while (!done && toWait > 0)
+ try {
+ return latch.await(timeout, TimeUnit.MILLISECONDS);
+ }
+ catch (InterruptedException e)
{
- try
- {
- wait(toWait);
- }
- catch (InterruptedException e)
- {
- }
-
- long now = System.currentTimeMillis();
-
- toWait -= now - start;
-
- start = now;
+ return false;
}
-
- return done;
}
- public synchronized void run()
+ public void run()
{
- done = true;
-
- notify();
+ latch.countDown();
}
+ @Override
+ public String toString()
+ {
+ return "Future(latch=" + latch + ")";
+ }
}
More information about the hornetq-commits
mailing list