Created
July 14, 2016 21:36
-
-
Save ykrkn/d3538dc8f6136c7e382580b31a2d7ebb to your computer and use it in GitHub Desktop.
CompletableFuture
This file contains 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
import java.util.concurrent.CompletableFuture; | |
import java.util.concurrent.atomic.AtomicLong; | |
import java.util.function.Consumer; | |
import java.util.function.Supplier; | |
/** | |
* Created by sx on 26.02.16. | |
*/ | |
public class Main implements Supplier<Double>, Consumer, Runnable{ | |
private final AtomicLong cnt = new AtomicLong(); | |
public static void main(String[] args){ | |
System.out.println("RUN"); | |
new Main().run0(); | |
} | |
private void run0(){ | |
CompletableFuture.supplyAsync(this) | |
.thenApply(x -> Math.sqrt(x)) | |
.thenApply(x -> Math.sqrt(x)) | |
.thenAccept(x -> System.out.print(x)) | |
.thenRun(Main.this); | |
} | |
@Override | |
public Double get() { | |
return 256.0 ;//Math.random(); | |
} | |
@Override | |
public void accept(Object o) { | |
System.out.println(o); | |
try { | |
Thread.sleep(111); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
} | |
public void run(){ | |
try { | |
Thread.sleep(7777); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment