Hi all, here is a question from http://www.javacross.com simulation please help me for a solution. Q].You are updating some data and is result of some calculations. When your thread performs an integer division by 0 causing an ArithmeticException, you have no catch code, which of these will happen a].the application will terminate b].the JVM will start a new thread to perform the update operation c].the application will not terminate but the updating will cease d].none of the above will happen
Your application may or may not terminate. Whenever there is an uncaught exception in a thread, that thread dies. Ofcourse if your program has only 1 non-daemon thread, i.e. user-thread (for eg. only a main thread), then JVM will exit. Otherwise if there are multiple daemon threads running, then the other threads will happily continue to run and JVM will not exit.
i agree with u Junaid Noel try this code and u will get the answer public class A extends Thread{ static int i=0; public void run() { System.out.println("all done before"+i); if (i ==0) i = 1/i; System.out.println("all done"+i); } public static void main(String[] args){ A t1 = new A(); t1.start(); try{ sleep(200);}catch (Exception e){} i++; A t2 = new A(); t2.start(); System.out.println("all done. exiting now"); } }