Question about StructuredTaskScope.joinUntil(Instant)

Werner Randelshofer werner.randelshofer at fibermail.ch
Wed May 29 05:39:52 UTC 2024


Hello everyone,

I have a question about StructuredTaskScope.joinUntil(Instant).

I am implementing a solver algorithm that has an execution time limit. 
The solver spawns sub-tasks and gathers all results that have been computed within the time limit.
I made a proof-of-concept that uses StructuredTaskScope.joinUntil(Instant) to define the deadline as Instant.now().plus(30, ChronoUnit.SECONDS);


Now, I am concerned that the System clock changes unpredictably due to NTP, while the solver runs.
So that, as the solver spawns new sub-tasks, the deadline will not stay constant.

I noticed that the code in StructuredTaskScope.joinUntil(Instant) calls Instant.now() to compute a timeout for the deadline.
I tried to create a subclass that uses a Clock instance of my own that is based on an internal time source (System.nanoTime), but I could not do this, because method StructuredTaskScope.implJoin(Duration timeout) is private.

So my question is:

Is there a way to use the StructuredTaskScope deadline feature so that it does only rely on resources provided by the current process - instead of relying on System time over which the current process has no control?


With best regards,
Werner Randelshofer


More information about the loom-dev mailing list