Skip to content

Commit 65d57ae

Browse files
update comments
1 parent b8a0c67 commit 65d57ae

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/main/java/multithread/completablefutureexamples/CompletableFutureDemo.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,20 @@ public static void main(String... args) throws Exception {
1919

2020
private static void runApp() throws InterruptedException, ExecutionException {
2121
Future<String> completableFuture = calculateAsync();
22+
System.out.println("got completableFuture: " + completableFuture);
23+
System.out.println("got completableFuture.isDone(): " + completableFuture.isDone());
2224
String result = completableFuture.get();
25+
System.out.println("got completableFuture.isDone(): " + completableFuture.isDone());
2326
assertEquals("Hello", result);
2427
}
2528

2629
private static Future<String> calculateAsync() {
2730
CompletableFuture<String> completableFuture = new CompletableFuture<>();
2831

2932
Executors.newCachedThreadPool().submit(() -> {
30-
Thread.sleep(1000);
3133
System.out.println("Doing some work in the thread now..");
34+
Thread.sleep(1000);
35+
System.out.println("Almost done working in the thread now..");
3236
completableFuture.complete("Hello");
3337
return null;
3438
});

src/main/java/multithread/completablefutureexamples/CompletableFutureDemo2.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,16 @@ public static void main(String... args) throws ExecutionException, InterruptedEx
2323
List<Future<String>> futureList = new ArrayList<>();
2424
for (int i = 1; i <= NUMBER_OF_COMPUTATION_JOBS; i++) {
2525
Future<String> completableFuture = workerPool.executeAsync(i);
26+
System.out.println("i = " + i + " and completableFuture.isDone() is: " + completableFuture.isDone());
2627
futureList.add(completableFuture);
2728
}
2829
for (Future<String> future : futureList) {
2930
String result = future.get();
3031
finalResult += Integer.parseInt(result);
3132
}
3233
long end = System.currentTimeMillis();
33-
System.out.println("end: " + end);
34-
System.out.println("start: " + start);
34+
System.out.println("end time in millis: " + end);
35+
System.out.println("start time in millis: " + start);
3536
System.out.println("It took " + (end - start) / 1000
3637
+ " seconds to complete computation, final result: " + finalResult
3738
+ ", a total of " + NUMBER_OF_COMPUTATION_JOBS + " computation jobs "

0 commit comments

Comments
 (0)