You are not logged in.
I was thinking something like this:
public class A {
public static int intMain(String... argv) {
///real program here
}
public static void main(String... argv) {
System.exit(intMain(argv));
}
}But System.exit does not await user threads and I use a library which creates threads where I do not have control.
Is there a way to await every user thread without explicitly knowing them?
Offline
All I can tell you is that this isn't C/C++. Java is a very different language, with a very different programming methodology. Using intMain in a Java program to me seems a overly complex...unless you're doing a switch/if else statement and returning runtime codes as integers in your System.exit function. In that case, I suppose it is useful.
What library are you using for threading?
Offline
I just want to return a value to the OS... zero in case of normal quit, non-zero in case of abnormal termination. I do not see anything complex in that. Actually it I think is crazy that Java mains are only void.
About threads I use rabbitmq and it uses threads for its messaging. I noticed the problem because if I forget to correctly close rabbitmq objects the ``void main'' does not terminate while the ``int main'' does since system.exit does not wait.
At the moment the question is more about curiosity, really there is no simple way to say ``await all users threads''?
Offline
If you want to return a value to the shell (C-style), depending on your program state on exit, use
// successful state
System.exit(0)
// erroneous state
System.exit(1)Last edited by hesse (2012-05-10 09:28:35)
Offline
This should work, as long as intMain does not return before the program is actually done.
You can explicitly make a thread wait for another one to complete, but I wont start explaining the whole java threading model here, there are very good tutorials online.
public class A {
public static int intMain(String... argv) {
///real program here
}
public static void main(String... argv) {
final int code = intMain(argv);
System.exit(code);
}
}Offline