SHARE
TWEET

Untitled

a guest Dec 13th, 2018 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top