Last active
December 14, 2015 08:39
-
-
Save mgodave/5059564 to your computer and use it in GitHub Desktop.
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
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