fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.util.concurrent.CompletableFuture;
  7. import java.lang.Thread;
  8.  
  9. /* Name of the class has to be "Main" only if the class is public. */
  10. class Ideone
  11. {
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14. CompletableFuture<Void> s = new CompletableFuture();
  15. CompletableFuture<Void> f = new CompletableFuture();
  16.  
  17. CompletableFuture<Void> someContext = CompletableFuture.supplyAsync(() ->
  18. {
  19. try{
  20.  
  21.  
  22. System.out.println(Thread.currentThread().getId());
  23. CompletableFuture<String> update =
  24. CompletableFuture.supplyAsync(
  25. () -> {
  26. String ans = null;
  27. try {
  28. System.out.println(Thread.currentThread().getId());
  29. ans = "Hello";
  30. } catch (Exception e) {
  31. ans = e.toString();
  32. } finally {
  33. s.complete(null);
  34. return ans;
  35. }
  36. });
  37. s.get();
  38. System.out.println(s.isDone());
  39. } catch (Exception e) {
  40. System.out.println("Some error");
  41. return null;
  42. }
  43. return null;
  44. });
  45.  
  46. System.out.println(f.isDone());
  47. }
  48. }
Success #stdin #stdout 0.1s 52144KB
stdin
Standard input is empty
stdout
false
10
12
true