File tree Expand file tree Collapse file tree 3 files changed +16
-9
lines changed
egg_8_sc_custom_invoke_some/src/main/java/net/codetojoy Expand file tree Collapse file tree 3 files changed +16
-9
lines changed Original file line number Diff line number Diff line change 1+
2+ package net .codetojoy ;
3+
4+ class Constants {
5+ static final int NUM_TASKS = 20 ;
6+ static final int NUM_TASKS_FOR_SUCCESS = 5 ;
7+ static final int MAX_DELAY_IN_SECONDS = 6 ;
8+ static final int PATHOGEN_THRESHOLD = 3 ; // 30% chance of failure
9+ }
Original file line number Diff line number Diff line change 22// note: I no longer own this domain
33package net .codetojoy ;
44
5+ import static net .codetojoy .Constants .*;
6+
57import java .util .*;
68import java .util .stream .IntStream ;
79import java .util .concurrent .*;
810
9- // javadoc here: https://download.java.net/java/early_access/jdk19/docs/api/jdk.incubator.concurrent/jdk/incubator/concurrent/package-summary.html
10-
1111public class Runner {
1212 private final Random random = new Random (System .currentTimeMillis ());
13- private static final int MAX_DELAY_IN_SECONDS = 6 ;
1413
1514 String taskFoo (int i ) {
1615 long delayInMillis = (random .nextInt (MAX_DELAY_IN_SECONDS ) + 1 ) * 1000L ;
@@ -23,11 +22,9 @@ String taskFoo(int i) {
2322 }
2423
2524 List <String > run () throws Exception {
26- int numTasksForSuccess = 5 ;
27- StructuredTaskScope .Joiner <String ,List <String >> joiner = new CustomJoiner (numTasksForSuccess );
25+ StructuredTaskScope .Joiner <String ,List <String >> joiner = new CustomJoiner (NUM_TASKS_FOR_SUCCESS );
2826 try (var scope = StructuredTaskScope .open (joiner )) {
29- int numTasks = 50 ;
30- IntStream .range (0 , numTasks ).forEach (i -> scope .fork (() -> taskFoo (i )));
27+ IntStream .range (0 , NUM_TASKS ).forEach (i -> scope .fork (() -> taskFoo (i )));
3128
3229 return scope .join ();
3330 }
Original file line number Diff line number Diff line change 22// note: I no longer own this domain
33package net .codetojoy ;
44
5+ import static net .codetojoy .Constants .*;
6+
57import java .time .Duration ;
68
79class Worker {
8- public static final int pathogenThreshold = 3 ;
910 public static final long THROW_EXCEPTION = -1L ;
1011 public static final String LOG_PREFIX = "TRACER Worker: " ;
1112
@@ -28,7 +29,7 @@ boolean isPathogenic() {
2829 int min = 1 ;
2930 int max = 10 ;
3031 int randomNum = min + (int )(Math .random () * ((max - min ) + 1 ));
31- return randomNum < pathogenThreshold ;
32+ return randomNum < PATHOGEN_THRESHOLD ;
3233 }
3334
3435 // see https://stackoverflow.com/questions/15160782
You can’t perform that action at this time.
0 commit comments