Skip to content

Commit

Permalink
Corrections
Browse files Browse the repository at this point in the history
Signed-off-by: Rafael Ibasco <[email protected]>
  • Loading branch information
ribasco committed Jun 28, 2022
1 parent d915b9e commit 08e0187
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions site/markdown/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Other supported protocols

### Best Practices

Keep in mind that you should **NEVER BLOCK** the thread of your completion handlers. If you have to perform synchronization within your handlers/callbacks, then it is highly recommended that you execute them asynchronously, otherwise your application may
Keep in mind that you should **NEVER BLOCK** the thread of your completion handlers. If you have to perform synchronization or a long running operation within your handlers/callbacks, then it is highly recommended that you execute them asynchronously, otherwise your application may
hang indefinitely.
Java's [CompletableFuture](https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletableFuture.html) provides a convenient way of executing your handlers asynchronously. Refer to the working examples below.

Expand Down Expand Up @@ -254,10 +254,11 @@ public class RecommendedExampleOne {
}
```

The problem with this approach is that its not efficient. A closer look at the `parseOutput` implementation, shows that it is calling `client.execute(...).join()` synchronously. The call to `join()` blocks the current thread until a response is received. A slightly better approach would be to execute all these additional requests asynchronously then use a synchronization barrier (e.g. `CountDownLatch` or `Phaser`) to block until all requests have been fulfilled. In this example, we will
The problem with this approach is that it's not efficient. A closer look at the `parseOutput` implementation, shows that it is calling `client.execute(...).join()` synchronously and will block the current thread until the method completes. The call to `join()` blocks the current thread until a response is received. A slightly better approach would be to execute all these additional requests asynchronously then use a synchronization barrier (e.g. `CountDownLatch` or `Phaser`) to block until all
requests have been fulfilled. In this example, we will
use `Phaser` since we do not yet know how many cvars we are going to process.

**Solution 2:** Update `parseOutput` implementation so that we requests for `help <cvar>` are all executed asynchronously then wait until all requests have been fulfilled.
**Solution 2:** Update `parseOutput` implementation so that the requests for `help <cvar>` are all executed asynchronously then wait until all requests have been fulfilled.

```java
import java.util.concurrent.CompletableFuture;
Expand Down

0 comments on commit 08e0187

Please sign in to comment.