I'm considering separating a task from my main program to a new (java) thread. The second task can be resource consuming (which raises concerns about the "wellbeing" of the main program).
Is there a difference between running the second task as a complete separate process (as if I were invoking it from command line), vs. running it in a new java thread?
This link gives an insight over the underlying Thread implementation in Solaris (a 1-1 mapping between Java and Kernel th开发者_开发技巧reads).
What can I expect on Linux?
Thanks,
Ariel
Generally speaking, running as a separate process entails a heavier separation of tasks than does running it as a separate thread. If the tasks need to share in-memory state, then that would drive you toward the thread-based implementation. Otherwise, a separate process might make sense.
The "well-being" concern you mention--that is a real concern. If the tasks are logically separable then it makes sense to use a separate process here since you don't want the resource-intensive process to break the other one. Different load characteristics often means that you want to be able to pull one task out and move it to an infrastructure that can better support it.
I don't think thread implementation specifics should be the driving factor here. The decision between using a process and using a thread lives at a higher level.
Things you can consider:
- Is there any communication between them. If yes, then remember that inter-process communication is complicated than inter-thread communication.
- If there is a possibility that you can achieve performance by separating the second task in to a different machine(maybe in future even) than separating in to a process might be beneficial.
- Does separating them in to 2 process increase deployment/management issues?
精彩评论