Branching:
You cannot pass a socket descriptor between Java processes using the regular API, as far as I can tell. However, this is similar to windows using the Winsock 2 API . In Posix, you should be able to unlock a child process with access to the parent socket, since forked processes inherit the parent sockets .
You can, I suppose, implement a new SocketImpl class that supports moving a socket descriptor to another process, but you need to write some JNI code for this.
Sounds pretty hairy to me, I doubt the new process from Java is a good idea!
Listeners:
Another approach may be to create a new βlistenerβ process, which is essentially a new pre-bifurcated employee. Each worker could take turns listening on a socket for connections. Workers will then need to coordinate work with a management process that manages the emergence of new processes as needed.
I agree with @Bozho, if an error in one thread can completely remove them (I think this should be a JVM exception that kills the whole application), you have a big problem. You should look at threading if possible.
source share