Created
July 10, 2021 23:06
-
-
Save pablohdzvizcarra/7f5b9c8d9c9d8f371f592ebad96682e6 to your computer and use it in GitHub Desktop.
run only one async task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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