Mercurial Hosting > nabble
comparison src/fschmidt/util/java/FastFuture.java @ 68:00520880ad02
add fschmidt source
| author | Franklin Schmidt <fschmidt@gmail.com> |
|---|---|
| date | Sun, 05 Oct 2025 17:24:15 -0600 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 67:9d0fefce6985 | 68:00520880ad02 |
|---|---|
| 1 package fschmidt.util.java; | |
| 2 | |
| 3 import java.util.concurrent.Callable; | |
| 4 import java.util.concurrent.ExecutionException; | |
| 5 import java.util.concurrent.Future; | |
| 6 import java.util.concurrent.FutureTask; | |
| 7 import java.util.concurrent.TimeUnit; | |
| 8 | |
| 9 | |
| 10 public final class FastFuture<V> implements Future<V> { | |
| 11 private volatile V result; | |
| 12 private volatile FutureTask<V> futureTask; | |
| 13 | |
| 14 public FastFuture(Callable<V> callable) { | |
| 15 futureTask = new FutureTask<V>(callable); | |
| 16 } | |
| 17 | |
| 18 public void run() { | |
| 19 FutureTask<V> ft = futureTask; | |
| 20 if( ft != null ) { | |
| 21 ft.run(); | |
| 22 } | |
| 23 } | |
| 24 | |
| 25 public boolean cancel(boolean mayInterruptIfRunning) { | |
| 26 throw new UnsupportedOperationException(); | |
| 27 } | |
| 28 | |
| 29 public boolean isCancelled() { | |
| 30 return false; | |
| 31 } | |
| 32 | |
| 33 public boolean isDone() { | |
| 34 return futureTask == null; | |
| 35 } | |
| 36 | |
| 37 public V get() throws InterruptedException, ExecutionException { | |
| 38 FutureTask<V> ft = futureTask; | |
| 39 if( ft != null ) { | |
| 40 result = ft.get(); | |
| 41 futureTask = null; | |
| 42 } | |
| 43 return result; | |
| 44 } | |
| 45 | |
| 46 public V get(long timeout,TimeUnit unit) { | |
| 47 throw new UnsupportedOperationException(); | |
| 48 } | |
| 49 | |
| 50 } |
