I have three classes: alpha, beta, gamma and each of the three classes has a main method.
Both alpha and beta classes have a try...catch...finally block inside their main method, for example:
public class alpha{ public static void main(String[] args){ try{ Do something; }catch(Exception ex){ ex.printStackTrace(); } finally{ System.exit(0); } } } public class beta{ public static void main(String[] args){ try{ Do something; }catch(Exception ex){ ex.printStackTrace(); } finally{ System.exit(0); } } }
Now, in the gamma class, I call the main alpha and beta classes to run continuously, as shown below
public gamma{ public static void main(String[] args) { try { alpha.main(arg); beta.main(arg1); } catch (Exception e) { e.printStackTrace(); } }
The problem is that beta.main(arg1) code is never reached due to System.exit(0) inside the finally alpha block class. Since alpha and beta are standalone applications, when they are run separately, they must stop servicing at the end of the program. So, now this is a way to reach the beta.main(arg1) without significantly changing the actual functionality of the alpha and beta classes.
Please let me know if you need more information. Thanks in advance...
source share