https://issues.apache.org/bugzilla/show_bug.cgi?id=57478

            Bug ID: 57478
           Summary: Using non-blocking "Future" instead of blocking
                    "Future.get" to improve performance?
           Product: Tomcat 8
           Version: trunk
          Hardware: PC
                OS: Mac OS X 10.1
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Catalina
          Assignee: dev@tomcat.apache.org
          Reporter: yu.lin...@gmail.com

Hi, I'm doing research on asynchronous programming. I found in many places, the
code in Tomcat 8 invokes "Future.get()" immediately after starting a future
task. Because "Future.get()" is a blocking call, the code will block
immediately. 

For example, in "startInternal" method of "ContainerBase" class (line 917), you
invoke "result.get()", where "result" is a Future, immediately after starting
it, so the code blocks immediately. Such code has the same effect as sequential
code (or even worse since you need to use other threads). 

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 "ContainerBase" class, you may put the code after
"result.get()" (such as lines 924-937) into CompletableFuture.thenRunAsync.
Then make "startInternal" method return this CompletableFuture, and in the
callers (such as "LifecycleBase.start()" method) you can put more continuations
into CompletableFuture.thenRunAsync. And you can also invoke "Future.get"
somewhere in the callers, instead of immediately. 

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

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to