Skip to content

Instantly share code, notes, and snippets.

@jordanglassman
Last active October 12, 2017 14:51
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 jordanglassman/e76806145032e93b5d334ee99af8a17b to your computer and use it in GitHub Desktop.
Save jordanglassman/e76806145032e93b5d334ee99af8a17b to your computer and use it in GitHub Desktop.
import org.apache.commons.codec.digest.DigestUtils;
import org.junit.Test;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
public class SandboxTest {
@Test
public void test() throws InterruptedException {
ExecutorService refreshExecutor = Executors.newFixedThreadPool(2);
Future<?> future = refreshExecutor.submit((Runnable) () -> {
try {
while (true) {
DigestUtils.md5(UUID.randomUUID().toString());
}
} catch (Exception e) {
} finally {
System.out.println("Exiting Runnable");
}
});
System.out.println("Sleep for 5 before terminating the above task");
Thread.sleep(5000);
System.out.println("Calling cancel ...");
future.cancel(true);
System.out.println("Cancel called");
Thread.sleep(5000);
System.out.println("Done ... exiting");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment