Search code examples
javamultithreadingrmi

Keeping the same thread name over RMI


Is there any tidy way to keep the same thread name when making an RMI call? At the moment if I have a named thread that makes an RMI call, on the server side of the RMI call, Thread.currentThread().getName() returns something un-illuminating like "RMI TCP Connection(4)-10.0.0.2".

Of course, I could go and add to all my RMI methods a parameter String callingThreadName and make the first line of each RMI method implementation Thread.currentThread().setName(callingThreadName), but that's hardly the neatest way of doing so. Is there any way to get at least some of the meaning behind the thread name transferred over the RMI connection?


Solution

  • The Java RMI Specification specifically states that there are no guarantees about how client calls are mapped to server threads. So you can make no assumptions about it. Specifically, you shouldn't be trying to use a thread identifier to correlate clients.