Last active
August 29, 2015 14:12
-
-
Save antsmartian/341a73c23131fa5621cc to your computer and use it in GitHub Desktop.
Parallel Computation in Groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.concurrent.* | |
import java.util.concurrent.ExecutorService; | |
import java.util.concurrent.Future; | |
import java.util.function.Function; | |
ExecutorService executor = Executors.newFixedThreadPool(2); | |
def <A> Future<A> run(ExecutorService s, Closure<Future<A>> a) { | |
a(s) | |
} | |
//type Par[A] = ExecutorService => Future[A] | |
def cls = { ExecutorService s -> | |
return executor.submit( new Thread(new CustomThread()) ) | |
} | |
class CustomThread implements Runnable{ | |
@Override | |
public void run() | |
{ | |
println 'Hello' | |
} | |
} | |
class FutureCustom<T> implements Future<T> { | |
@Override | |
public boolean cancel(boolean mayInterruptIfRunning) { | |
return false; | |
} | |
@Override | |
public boolean isCancelled() { | |
return false; | |
} | |
@Override | |
public boolean isDone() { | |
return false; | |
} | |
@Override | |
public T get() throws InterruptedException, ExecutionException { | |
return null; | |
} | |
@Override | |
public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { | |
return null; | |
} | |
} | |
def future = run(executor,cls) | |
future.get() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment