Created
August 23, 2012 15:27
-
-
Save sherman/3437750 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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