Skip to content

Instantly share code, notes, and snippets.

@antsmartian
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antsmartian/341a73c23131fa5621cc to your computer and use it in GitHub Desktop.
Save antsmartian/341a73c23131fa5621cc to your computer and use it in GitHub Desktop.
Parallel Computation in Groovy
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