I have implemented a multi-threaded program which involves spawning a thread for each user,and performing some minor activities(No exhaustive processes like database connection involved).The main thread runs infinitely,and its termination is handled via monitoring file creation activity.
My question is, is it okay to terminate the main thread straightaway,without waiting for the threads to finish ? (assuming that the threads would complete on their own(!),could be a false assumption).
I have implemented a multi-threaded program which involves spawning a thread for each user,and
Share
Sure.
The main thread is just one thread amongst others and its termination won’t affect the other threads (unless you don’t use
System.exit()to stop the thread…).The main thread is just the first thread*) that has been started but it has no extra or hidden features or functionalities.
*) to keep it simple – the jvm may have started some internal threads before main – but the application has no code for those threads