You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@uima.apache.org by "Yu Lin (JIRA)" <de...@uima.apache.org> on 2015/01/21 22:49:34 UTC

[jira] [Created] (UIMA-4197) Using non-blocking "Future" instead of blocking "Future.get" to improve performance?

Yu Lin created UIMA-4197:
----------------------------

             Summary: Using non-blocking "Future" instead of blocking "Future.get" to improve performance?
                 Key: UIMA-4197
                 URL: https://issues.apache.org/jira/browse/UIMA-4197
             Project: UIMA
          Issue Type: Improvement
          Components: DUCC
            Reporter: Yu Lin
            Priority: Minor


Hi, I'm doing research on asynchronous programming. I found at some places, the code in uima-ducc ("trunk" branch) invokes "Future.get()" immediately after starting a future task. Because "Future.get()" is a blocking call, the code will block immediately. 

For example, in "startAgents" method of "DuccAdmin" class (line 296), you invoke "result.get()", where "result" is a Future, immediately after starting future tasks, so the code blocks immediately. Such code has the same effect as sequential code. 

Why not use Guava ListenableFuture or Java8 CompletableFuture and avoid "Future.get()"? These two new constructs provide callbacks to listen to the Future's result:
http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/util/concurrent/ListenableFuture.html

https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletableFuture.html

For example, in "DuccAdmin" class, you may put the code after "result.get()" (such as lines 301-307) into "CompletableFuture.thenRunAsync" method.
Then make "startAgents" method return this CompletableFuture, and in the callers (such as "DuccAdmin.process()" or "DuccAdmin.main" method) you can put more continuations into "CompletableFuture.thenRunAsync". And you can also invoke "Future.get" somewhere in the callers (for example in "DuccAdmin.process()" method), instead of immediately. 

Do you think such kind of change is correct and can improve the code?



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)