Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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