SOAP::RPC::StandaloneServer failed in the thread

I wrote a simple soap server as below

NS = ‘’;
class Server < SOAP::RPC::StandaloneServer
def on_init
t =
add_method(t, ‘echo’)
svr =‘TEST’,NS,‘’,12321)
trap(‘INT’) {svr.shutdown}

it can run without problem. However if I run the same piece of code in
a thread, it will not work do

#same code here

#wait for the thread

I think the server does not start because the listening port I
specified is not occupied by any application. Does anyone know what
the problem is?