1 package com.twister; 2 import java.io.PrintStream; 3 4 public class StopTheLoop { 5 static StopTheLoop looper; 6 7 public StopTheLoop() { 8 PrintStream ps = new PrintStream(System.out){ 9 @Override 10 public void println(String x) { 11 super.println(x); 12 System.exit(0); 13 } 14 }; 15 System.setOut(ps); 16 } 17 18 public static void main(String[] args) { 19 looper = new StopTheLoop(); 20 looper = null; 21 do{ 22 System.out.println("Infinite Loop");; 23 }while(looper==null); 24 } 25 }