Usage of CompletableFuture

Java 8 gives flexible ways to perform asynchronous tasks. One of a such ways is usage of CompletableFuture.

Simple Usage of CompletableFuture

The code demonstrates simple usage of CompletableFuture:

  • Perform a work asynchronously and get a result synchronously
  • Perform a work asynchronously and get a result after a some time.

Usage of CompletableFuture in chain

The code demonstrates usage of CompletableFuture in chains:

  • Perform a work and accept a result – everything asynchronously
  • Perform a work1,then a work2, and accept a result – everything asynchronously

Simple Error Handling

The code demonstrates error handling when CompletableFuture is used without chain.

Error Handling in Chains

The code demonstrates error handling when CompletableFuture is used with chain.

Advertisements

About ysden123

We are not only for work... All my time free from work I spend on photography. Most photos are from our travels. I like make photos in still life style as well.
This entry was posted in java, Programming and tagged , , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s