Skip to content

Instantly share code, notes, and snippets.

@mgodave
Last active December 14, 2015 08:39
Show Gist options
  • Save mgodave/5059564 to your computer and use it in GitHub Desktop.
Save mgodave/5059564 to your computer and use it in GitHub Desktop.
package org.robotninjas.audio;
import com.google.common.util.concurrent.*;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import static com.google.common.util.concurrent.MoreExecutors.listeningDecorator;
import static java.util.concurrent.Executors.newCachedThreadPool;
import static java.util.concurrent.Executors.newScheduledThreadPool;
public class DelayQueueExample {
public static void main(String[] args) throws ExecutionException, InterruptedException {
final ListeningScheduledExecutorService scheduledExecutor = listeningDecorator(newScheduledThreadPool(1));
final ListeningExecutorService executor = listeningDecorator(newCachedThreadPool());
final ScheduledFuture<ListenableFuture<Void>> g = scheduledExecutor.schedule(new Callable<ListenableFuture<Void>>() {
@Override
public ListenableFuture<Void> call() throws Exception {
return executor.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
System.out.println("Hello World");
return null;
}
});
}
}, 5, TimeUnit.SECONDS);
Futures.getUnchecked(g.get());
scheduledExecutor.shutdownNow();
executor.shutdownNow();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment