Guest User

Untitled

a guest
Dec 13th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. import org.junit.Test;
  2.  
  3. public class NewThreadTest {
  4.  
  5. public static void main(String[] args) {
  6. new Thread(new InfiniteRunnable()).start();
  7. //Thread will execute forever, but if we terminate the JVM with System.exit(0) - it will stop
  8. //System.exit(0);
  9. }
  10.  
  11. //Test will pass and Junit runner will terminate the JVM with System.exit(0)
  12. @Test
  13. public void test() {
  14. new Thread(new InfiniteRunnable()).start();
  15. }
  16.  
  17. private static class InfiniteRunnable implements Runnable {
  18.  
  19. @Override
  20. public void run() {
  21. while (true) {
  22. Thread.yield();
  23. }
  24. }
  25.  
  26. }
  27. }
Add Comment
Please, Sign In to add comment