Guest User

Untitled

a guest
Jan 19th, 2025
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. @Test
  2. public void testForcibleStop() throws InterruptedException {
  3. Thread thread = new Thread(() -> {
  4. while (true) {
  5. try {
  6. Thread.sleep(1000);
  7. System.out.println("I'm still running");
  8. } catch (InterruptedException e) {
  9. // Do nothing, keep going
  10. }
  11. }
  12. });
  13.  
  14. thread.start();
  15.  
  16. // Give the thread a chance to start
  17. Thread.sleep(2000);
  18.  
  19. try {
  20. thread.stop();
  21. } catch (UnsupportedOperationException e) {
  22. // Expected
  23. }
  24.  
  25. // Observe that the print statements keep coming
  26. Thread.sleep(10000);
  27. }
Advertisement
Add Comment
Please, Sign In to add comment