RMI threads

I have been reading about Java RMI online and I have seen few examples where the authors suggest that the main thread should only be used for initialization and registration and rest of the program's logic should be placed in a new thread.

I was wondering what will I gain by designing my program that way, instead of simply doing all the processing in the main thread?

I'll appreciate your help.

P.

[426 byte] By [PaperCuta] at [2007-10-2 5:48:06]
# 1
If you're talking about an RMI server you don't have any choice in the matter. The RMI runtime creates threads to service incoming calls.
ejpa at 2007-7-16 1:57:39 > top of Java-index,Core,Core APIs...
# 2

My question is about the RMI server, but I'm not talking about the threads that are automatically created by the RMI.

I have seen examples where people only use the main (original) thread in the RMI server for registration and other initialization tasks and then they create a new thread by calling the run method in the main method. This new thread is where most of the computation takes place.

I'm wondering why would we want to do this? What are the benefits? Someone told me that the main thread may not be as "light weight" as a thread started by the user, so we may save some overhead by starting a new thread.

P.

PaperCuta at 2007-7-16 1:57:39 > top of Java-index,Core,Core APIs...
# 3

I don't see how you could save overhead by creating another thread. Even then the overhead creating a new thread is very minimal. If the sequence of code to be executed is sequential, then don't bother with another thread.

They may have been referring to daemon threads, but those are no different than non-daemon threads as far as execution is concerned.

carr_onstotta at 2007-7-16 1:57:39 > top of Java-index,Core,Core APIs...
# 4
It could also be that someone simply wanted to kick off a long-running process on the server and let the remote call return.
bschauwejavaa at 2007-7-16 1:57:39 > top of Java-index,Core,Core APIs...