Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Test
- public void testForcibleStop() throws InterruptedException {
- Thread thread = new Thread(() -> {
- while (true) {
- try {
- Thread.sleep(1000);
- System.out.println("I'm still running");
- } catch (InterruptedException e) {
- // Do nothing, keep going
- }
- }
- });
- thread.start();
- // Give the thread a chance to start
- Thread.sleep(2000);
- try {
- thread.stop();
- } catch (UnsupportedOperationException e) {
- // Expected
- }
- // Observe that the print statements keep coming
- Thread.sleep(10000);
- }
Advertisement
Add Comment
Please, Sign In to add comment