Ive got a question. I write a Java Program which I start as a daemon. So I have a class where I implement Daemon and Runnable. In init()
I do some checks and then, when the checks are okay, I start a new thread.
thread = new Thread(this);
If the checks are not okay, I call stop()
.In stop I have this call:
thread.join();
But how would this possibly work, if I never created the new Thread. I would get a NullPointerException
. How should I handle this problem? Catch NullPointerException
? Only call thread.join()
if thread is not null? Dont call thread.join()
? What would be the best way and why? Thank you :-)
The reason I asked this question is just that I never implemented a daemon before and I wasnt sure how to handle threads there. Maybe I shouldnt have asked. Thanks anyway.