Skip to content

Instantly share code, notes, and snippets.

@pablohdzvizcarra
Created July 10, 2021 23:06
Show Gist options
  • Save pablohdzvizcarra/7f5b9c8d9c9d8f371f592ebad96682e6 to your computer and use it in GitHub Desktop.
Save pablohdzvizcarra/7f5b9c8d9c9d8f371f592ebad96682e6 to your computer and use it in GitHub Desktop.
run only one async task
package org.async;
import java.util.concurrent.CompletableFuture;
public class Main
{
public static void main(String[] args)
{
// TODO: 7/10/21 Create a simple Task
// TODO: 7/10/21 Add sleep to thread, for the asynchronous task to be executed
CompletableFuture.runAsync(
() -> System.out.println("I am running asynchronously"));
// If only one asynchronous task is added to the main thread, this asynchronous
// task will never be executed since the main thread has no other task to perform
try
{
Thread.sleep(100);
} catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment