User Tools

Site Tools


futures

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
futures [2026/07/10 07:33] – created carlfutures [2026/07/10 07:43] (current) carl
Line 1: Line 1:
 ====== Futures ====== ====== Futures ======
  
-Futures are a complex, heterogeneous feature.  Each language handles them slightly differently.  Most of the discussion here is for Java.+Futures are a complex, heterogeneous feature.  Each language handles them slightly differently.  Most of the discussion here is for [[java:futures|Java]].
  
 A future has 3 parties involved in the lifecycle. A future has 3 parties involved in the lifecycle.
Line 9: Line 9:
   - The Waiter.  This party (possibly multiple threads), awaits the results set by the Fulfiller.   - The Waiter.  This party (possibly multiple threads), awaits the results set by the Fulfiller.
  
-In a typical scenario, these three parties are different threads, meaning there is a high amount of coordination between them.  +In a typical scenario, these three parties are different threads, meaning there is a high amount of coordination between them.  In Java syntax: 
 + 
 +<code java> 
 +Future<String> future = CompletableFuture.supplyAsync(() -> "a" + "b", executor); 
 +future.get(); 
 +</code> 
 + 
 +The party that creates the ''CompletableFuture'' object is the Scheduler.  It is the current thread.  The Fulfiller is the ''executor'', which is likely a ThreadPoolExecutor, or a Virtual Thread executor.  It will actually be running the provided lambda, and completing the future.  Finally, the current thread is acting as the Waiter.  It does so by calling ''get()'', which puts it to sleep until the Fulfiller wakes it up.   
  
futures.1783668835.txt.gz · Last modified: by carl