public class TwoThreadsTest {
    public static void main (String[] args) throws Exception{
        Thread tj = new SimpleThread("Jamaica");
        Thread tf = new SimpleThread("Fiji");
        
        //tj.setDaemon(true); 
        //tf.setDaemon(true);
        
        tj.start();
        tf.start();
    
        System.out.println("<enter> to exit");
        System.in.read();
        
        tj.interrupt();
        tf.interrupt();
    }
}

class SimpleThread extends Thread {
    public SimpleThread(String name) {
        super(name);
    }
    
    public void run() {
        for (int i = 0; i < 10; i++) {
            System.out.println(i+" "+getName());
            
            try {
                sleep((long)(Math.random() * 2000));
            } catch (InterruptedException ex) {
                System.out.println("INTERRUPTED1! " + getName());
                return;
            }
            
            long s = 0;
            for (int j=0; j<1; j++) {
                for (int k=0; k<Integer.MAX_VALUE; k++) {
                    s += 1;
                }
            }
            
            if (interrupted()) {
                System.out.println("INTERRUPTED2! " + getName());
                return;
            }
        }
        System.out.println("DONE! " + getName());
    }
    
    private void Delay() {
         long s = 0;
         for (int k=0; k<Integer.MAX_VALUE; k++) {
              s += 1;
         }
   }
}
