Skip to content

csd #300

Description

@siddharthrgade21-a11y

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

public class AdvancedConcurrency {
public static void main(String[] args) throws ExecutionException, InterruptedException {
// Run a task asynchronously and process the result
CompletableFuture future = CompletableFuture.supplyAsync(() -> {
try { Thread.sleep(1000); } catch (InterruptedException e) {}
return "Data from Remote API";
});

    // Chain another task to the result
    future.thenAccept(result -> System.out.println("Processing: " + result))
          .get(); // Blocks until complete (for demo purposes)
}

}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions