On January 7, 2004 10:37 pm, Paul Mclachlan wrote: > Kok Choon Kiat wrote: > > It appears to me that the native thread has *seized the entire > > flow of control* from java program and it is not running > > independently. Why is that so? How can I make the native thread > > independent and not seize the flow of control from the java > > program? I would really appreciate if you can my answer my > > questions. Thank you very much. > > Add a "System.exit( 0 );" to the end of your main() method. > > When main() ends, all that means is that that thread has finished. > If your process has other (non-daemon) threads running, it will > continue to run until they finish, also. Unless you hard-terminate > the process. > > If you're trying to prove a point, you could add a random sleep in > before calling System.exit(0), then you'd see nondeterminism at > work and could be happy that it was doing what you wanted. > > On the other hand, if what you're after (and I can't tell from your > email, sorry), is that the "Hello World"'s keep printing even after > the java process has exited, you need a Runtime.exec() or fork(), > not a pthread_create(). I suspect you know this, but thought I'd > throw it in just in case.
I agree with what Paul said above and would also add that I recently read that one of the more recently JDK 1.4 versions also added the ability for Native threads to be 'daemon' threads. Which means the JVM will exit even if they are running. What JJ is seeing is a non-daemon native thread keeping his JVM from exiting, and I think he was surprised by that. Oh well, fun stuff to think about, but not exactly anything concerning Linux, other than the fact that it was the platform on which the behaviour was observed. Cheers. -Neal ---------------------------------------------------------------------- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]