Skip to content

Instantly share code, notes, and snippets.

@sherman
Created August 23, 2012 15:27
Show Gist options
  • Save sherman/3437750 to your computer and use it in GitHub Desktop.
Save sherman/3437750 to your computer and use it in GitHub Desktop.
ExecutorService s = Executors.newFixedThreadPool(10);
Future<?> f = s.submit(
new Runnable() {
@Override
public void run() {
try {
Context.enter();
// do stuff
} catch (Throwable e) {
} finally {
Context.exit();
}
}
}
);
try {
f.get(2, TimeUnit.SECONDS);
} catch (TimeoutException e) {
f.cancel();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment