Infinite Loop and System.exit(0) in java -
i wondering if bad coding practice and/or consequences if make infinite loop(i checking if program has started) , when condition im checking becomes true, use system.exit.
you may better off using java.util.timer , java.util.timertask classes, , recursively relaunching timer expires. above post says there nothing inherently wrong using system.exit.
public static void main(string[] args){ timer timer = new timer(); //create new timer timer.schedule(new taskloop(), 1000); //schedule task 1000ms (1 sec) } class taskloop extends timertask { public void run() { system.out.println("here"); //timer's up, whatever need timer timer = new timer(); timer.schedule(new taskloop(), 1000); //start timer. } }
Comments
Post a Comment