Last active
October 12, 2017 14:51
-
-
Save jordanglassman/e76806145032e93b5d334ee99af8a17b 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
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