You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by "Uday Prakash (DHL CZ)" <ud...@dhl.com> on 2007/03/20 16:38:10 UTC

Shutting down a server elegantly

Hi,

I've been working on a small tcp/ip server, that listens for specific
messages and then depending on the message type performs a particular
task. That was the easy part, I was looking into shutting down the
server in an elegant manner. I decided that I'll be listening on a
particular port say 'SHUTDOWN_PORT' and when I receive a pre-defined
message to shutdown, I shall shut the server down. 

To do so, I call on acceptor.unbindAll() and shutdown the executor
services. As the documentation points, but what I see is that the
threads continue to stay alive. Is there something I'm doing wrong? 

A little direction would help.

Thank You!

-U

RE: Shutting down a server elegantly

Posted by "Uday Prakash (DHL CZ)" <ud...@dhl.com>.
Hi Michael,

I am slightly ashamed to be putting this out there in the public forum
:-X

Here is what the problem was, the threads as indicated by Trustin were
initially not daemon. Secondly acceptor that I was calling unbindAll()
was not the acceptor what was bound. This lead me to realize that I
could use the same acceptor and bind numerous times, and then close just
one acceptor! After this was done, the server on receiving a message to
shut_down returned from my threads and waited for MINA to exit.

It was nothing beyond existential, it was very much poor programming on
my part ;-(

-U

-----Original Message-----
From: Michael Bauroth [mailto:michael.bauroth@falcom.de] 
Sent: Thursday, March 22, 2007 3:26 PM
To: dev@mina.apache.org
Subject: Re: Shutting down a server elegantly

Hi Uday,

could you please provide me with some more details about your solution?

Best Regards
Michael

Uday Prakash (DHL CZ) schrieb:
> Hi Trustin,
> 
> Well now the 'chicken' did hatch before I called it one! I solved the
> problem with the blocking thread! 
> Sorry if I took your time...
> 
> Must say MINA is making life a lot more interesting ;-)
> Cheerio!
> 
> -U



Re: Shutting down a server elegantly

Posted by Michael Bauroth <mi...@falcom.de>.
Hi Uday,

could you please provide me with some more details about your solution?

Best Regards
Michael

Uday Prakash (DHL CZ) schrieb:
> Hi Trustin,
> 
> Well now the 'chicken' did hatch before I called it one! I solved the
> problem with the blocking thread! 
> Sorry if I took your time...
> 
> Must say MINA is making life a lot more interesting ;-)
> Cheerio!
> 
> -U


RE: Shutting down a server elegantly

Posted by "Uday Prakash (DHL CZ)" <ud...@dhl.com>.
Hi Trustin,

Well now the 'chicken' did hatch before I called it one! I solved the
problem with the blocking thread! 
Sorry if I took your time...

Must say MINA is making life a lot more interesting ;-)
Cheerio!

-U

-----Original Message-----
From: Trustin Lee [mailto:trustin@gmail.com] 
Sent: Wednesday, March 21, 2007 4:27 AM
To: dev@mina.apache.org
Subject: Re: Shutting down a server elegantly

Hi Uday,

On 3/21/07, Uday Prakash (DHL CZ) <ud...@dhl.com> wrote:
> Hi,
>
> I've been working on a small tcp/ip server, that listens for specific
> messages and then depending on the message type performs a particular
> task. That was the easy part, I was looking into shutting down the
> server in an elegant manner. I decided that I'll be listening on a
> particular port say 'SHUTDOWN_PORT' and when I receive a pre-defined
> message to shutdown, I shall shut the server down.
>
> To do so, I call on acceptor.unbindAll() and shutdown the executor
> services. As the documentation points, but what I see is that the
> threads continue to stay alive. Is there something I'm doing wrong?
>
> A little direction would help.

All remaining threads should be daemon threads once the port is
unbound, and therefore the VM should exit automatically.   If the VM
doesn't exit automatically, please capture the full thread dump after
unbindAll() operation, and send it here so we can analyze the cause of
the problem.

HTH,
Trustin
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6


Re: Shutting down a server elegantly

Posted by Trustin Lee <tr...@gmail.com>.
Hi Niklas,

On 3/22/07, Niklas Therning <ni...@trillian.se> wrote:
> Trustin is referring to a dump of all threads in the JVM. This will show
> a full stack trace for each thread, what locks they have acquired and
> whether they are waiting for any locks. It's essential when detecting
> deadlocks and other thread related issues. Here's more info on how to
> generate a thread dump:
> http://qa.netbeans.org/bugzilla/generating-thread-dumps.html

Thanks for a great resource.  I will add this link to our web site.

Trustin
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6

Re: Shutting down a server elegantly

Posted by Niklas Therning <ni...@trillian.se>.
Trustin is referring to a dump of all threads in the JVM. This will show 
a full stack trace for each thread, what locks they have acquired and 
whether they are waiting for any locks. It's essential when detecting 
deadlocks and other thread related issues. Here's more info on how to 
generate a thread dump: 
http://qa.netbeans.org/bugzilla/generating-thread-dumps.html

/Niklas

Mark Webb wrote:
> you could do something like:
>
> new Throwable().printStackTrace();
>
>
>
> On 3/21/07, Nicolas FROMENT <nf...@histor.fr> wrote:
>>
>>
>> Hi all !
>> I think I have the same problem. Only on linux, when I shutdown my
>> server and try to restart it immediatly I got an Address Already In Use
>> message.
>> I use unbindAll too. I wonder if unbindAll is synchronous. I mean after
>> calling it may I consider that the port is unbound  or no ? Trustin, you
>> ask about "capturing the full thread dump" after the call, What do you
>> mean and how can I do this ?
>>
>> Thks for your help
>>
>> Nicolas
>>
>> Uday Prakash (DHL CZ) a écrit :
>> > Hi Trustin,
>> >
>> > Thank you for that suggestion, I shall look into it.
>> >
>> > -U
>> >
>> > -----Original Message-----
>> > From: Trustin Lee [mailto:trustin@gmail.com]
>> > Sent: Wednesday, March 21, 2007 4:27 AM
>> > To: dev@mina.apache.org
>> > Subject: Re: Shutting down a server elegantly
>> >
>> > Hi Uday,
>> >
>> > On 3/21/07, Uday Prakash (DHL CZ) <ud...@dhl.com> wrote:
>> >
>> >> Hi,
>> >>
>> >> I've been working on a small tcp/ip server, that listens for specific
>> >> messages and then depending on the message type performs a particular
>> >> task. That was the easy part, I was looking into shutting down the
>> >> server in an elegant manner. I decided that I'll be listening on a
>> >> particular port say 'SHUTDOWN_PORT' and when I receive a pre-defined
>> >> message to shutdown, I shall shut the server down.
>> >>
>> >> To do so, I call on acceptor.unbindAll() and shutdown the executor
>> >> services. As the documentation points, but what I see is that the
>> >> threads continue to stay alive. Is there something I'm doing wrong?
>> >>
>> >> A little direction would help.
>> >>
>> >
>> > All remaining threads should be daemon threads once the port is
>> > unbound, and therefore the VM should exit automatically.   If the VM
>> > doesn't exit automatically, please capture the full thread dump after
>> > unbindAll() operation, and send it here so we can analyze the cause of
>> > the problem.
>> >
>> > HTH,
>> > Trustin
>> >
>>
>>
>> -- 
>> ******************************************************************
>> Nicolas Froment         nfroment@histor.fr
>> Software Architect
>>
>> Hi-Stor Technologies        www.histor.fr
>> 23 bd Victor Hugo            Std:    +33 (0) 562 12 14 40 (Voice)
>> Bâtiment Socrate             Fax:    +33 (0) 562 12 14 49
>> 31770 Colomiers
>> FRANCE
>>
>> ****************************************************************
>>
>>
>
>


Re: Shutting down a server elegantly

Posted by Mark Webb <el...@gmail.com>.
you could do something like:

new Throwable().printStackTrace();



On 3/21/07, Nicolas FROMENT <nf...@histor.fr> wrote:
>
>
> Hi all !
> I think I have the same problem. Only on linux, when I shutdown my
> server and try to restart it immediatly I got an Address Already In Use
> message.
> I use unbindAll too. I wonder if unbindAll is synchronous. I mean after
> calling it may I consider that the port is unbound  or no ? Trustin, you
> ask about "capturing the full thread dump" after the call, What do you
> mean and how can I do this ?
>
> Thks for your help
>
> Nicolas
>
> Uday Prakash (DHL CZ) a écrit :
> > Hi Trustin,
> >
> > Thank you for that suggestion, I shall look into it.
> >
> > -U
> >
> > -----Original Message-----
> > From: Trustin Lee [mailto:trustin@gmail.com]
> > Sent: Wednesday, March 21, 2007 4:27 AM
> > To: dev@mina.apache.org
> > Subject: Re: Shutting down a server elegantly
> >
> > Hi Uday,
> >
> > On 3/21/07, Uday Prakash (DHL CZ) <ud...@dhl.com> wrote:
> >
> >> Hi,
> >>
> >> I've been working on a small tcp/ip server, that listens for specific
> >> messages and then depending on the message type performs a particular
> >> task. That was the easy part, I was looking into shutting down the
> >> server in an elegant manner. I decided that I'll be listening on a
> >> particular port say 'SHUTDOWN_PORT' and when I receive a pre-defined
> >> message to shutdown, I shall shut the server down.
> >>
> >> To do so, I call on acceptor.unbindAll() and shutdown the executor
> >> services. As the documentation points, but what I see is that the
> >> threads continue to stay alive. Is there something I'm doing wrong?
> >>
> >> A little direction would help.
> >>
> >
> > All remaining threads should be daemon threads once the port is
> > unbound, and therefore the VM should exit automatically.   If the VM
> > doesn't exit automatically, please capture the full thread dump after
> > unbindAll() operation, and send it here so we can analyze the cause of
> > the problem.
> >
> > HTH,
> > Trustin
> >
>
>
> --
> ******************************************************************
> Nicolas Froment         nfroment@histor.fr
> Software Architect
>
> Hi-Stor Technologies        www.histor.fr
> 23 bd Victor Hugo            Std:    +33 (0) 562 12 14 40 (Voice)
> Bâtiment Socrate             Fax:    +33 (0) 562 12 14 49
> 31770 Colomiers
> FRANCE
>
> ****************************************************************
>
>


-- 
..Cheers
Mark

Re: Shutting down a server elegantly

Posted by Nicolas FROMENT <nf...@histor.fr>.
Hi all !
I think I have the same problem. Only on linux, when I shutdown my 
server and try to restart it immediatly I got an Address Already In Use 
message.
I use unbindAll too. I wonder if unbindAll is synchronous. I mean after 
calling it may I consider that the port is unbound  or no ? Trustin, you 
ask about "capturing the full thread dump" after the call, What do you 
mean and how can I do this ?

Thks for your help

Nicolas

Uday Prakash (DHL CZ) a écrit :
> Hi Trustin,
>
> Thank you for that suggestion, I shall look into it.
>
> -U
>
> -----Original Message-----
> From: Trustin Lee [mailto:trustin@gmail.com] 
> Sent: Wednesday, March 21, 2007 4:27 AM
> To: dev@mina.apache.org
> Subject: Re: Shutting down a server elegantly
>
> Hi Uday,
>
> On 3/21/07, Uday Prakash (DHL CZ) <ud...@dhl.com> wrote:
>   
>> Hi,
>>
>> I've been working on a small tcp/ip server, that listens for specific
>> messages and then depending on the message type performs a particular
>> task. That was the easy part, I was looking into shutting down the
>> server in an elegant manner. I decided that I'll be listening on a
>> particular port say 'SHUTDOWN_PORT' and when I receive a pre-defined
>> message to shutdown, I shall shut the server down.
>>
>> To do so, I call on acceptor.unbindAll() and shutdown the executor
>> services. As the documentation points, but what I see is that the
>> threads continue to stay alive. Is there something I'm doing wrong?
>>
>> A little direction would help.
>>     
>
> All remaining threads should be daemon threads once the port is
> unbound, and therefore the VM should exit automatically.   If the VM
> doesn't exit automatically, please capture the full thread dump after
> unbindAll() operation, and send it here so we can analyze the cause of
> the problem.
>
> HTH,
> Trustin
>   


-- 
******************************************************************
Nicolas Froment         nfroment@histor.fr
Software Architect
 
Hi-Stor Technologies        www.histor.fr
23 bd Victor Hugo            Std:    +33 (0) 562 12 14 40 (Voice)
Bâtiment Socrate             Fax:    +33 (0) 562 12 14 49
31770 Colomiers             
FRANCE
 
****************************************************************


RE: Shutting down a server elegantly

Posted by "Uday Prakash (DHL CZ)" <ud...@dhl.com>.
Hi Trustin,

Thank you for that suggestion, I shall look into it.

-U

-----Original Message-----
From: Trustin Lee [mailto:trustin@gmail.com] 
Sent: Wednesday, March 21, 2007 4:27 AM
To: dev@mina.apache.org
Subject: Re: Shutting down a server elegantly

Hi Uday,

On 3/21/07, Uday Prakash (DHL CZ) <ud...@dhl.com> wrote:
> Hi,
>
> I've been working on a small tcp/ip server, that listens for specific
> messages and then depending on the message type performs a particular
> task. That was the easy part, I was looking into shutting down the
> server in an elegant manner. I decided that I'll be listening on a
> particular port say 'SHUTDOWN_PORT' and when I receive a pre-defined
> message to shutdown, I shall shut the server down.
>
> To do so, I call on acceptor.unbindAll() and shutdown the executor
> services. As the documentation points, but what I see is that the
> threads continue to stay alive. Is there something I'm doing wrong?
>
> A little direction would help.

All remaining threads should be daemon threads once the port is
unbound, and therefore the VM should exit automatically.   If the VM
doesn't exit automatically, please capture the full thread dump after
unbindAll() operation, and send it here so we can analyze the cause of
the problem.

HTH,
Trustin
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6


Re: demarcating incoming messages

Posted by Trustin Lee <tr...@gmail.com>.
Hi Uday,

On 3/21/07, Uday Prakash (DHL CZ) <ud...@dhl.com> wrote:
> Hi Trustin,
>
> Is there a way to set up the framework so that when a message stream is
> received and messageReceived(...) is called we are able to extract
> individual messages from a stream of messages.
>
> Say, the messages start with <STX> and end with <ETX> so when we get a
> stream of bytes the messageReceived(...) method is called and only that
> part of the stream between <STX> and <ETX> comes in as a message object.

Sure.  MINA provides ProtocolCodecFilter, which decodes the incoming
ByteBuffers into your favorite plain old Java object.  Please refer to
a few examples which uses a protocol codec; SumUp, and Reverse Echo.

It will take you some time to understand how to implement your codec.
Please try to review our decoder and encoder implementations, and feel
free to ask questions here.  The following decoder classes could be
helpful for you.

* TextLineDecoder - http://tinyurl.com/37csqo
* ObjectSerializationDecoder - http://tinyurl.com/389ymp

> And thank you for that precious hint, I was able to get the Threads to
> die elegantly!

Good to hear that! :)

HTH,
Trustin
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6

demarcating incoming messages

Posted by "Uday Prakash (DHL CZ)" <ud...@dhl.com>.
Hi Trustin,

Is there a way to set up the framework so that when a message stream is
received and messageReceived(...) is called we are able to extract
individual messages from a stream of messages. 

Say, the messages start with <STX> and end with <ETX> so when we get a
stream of bytes the messageReceived(...) method is called and only that
part of the stream between <STX> and <ETX> comes in as a message object.

And thank you for that precious hint, I was able to get the Threads to
die elegantly!

-U

-----Original Message-----
From: Trustin Lee [mailto:trustin@gmail.com] 
Sent: Wednesday, March 21, 2007 4:27 AM
To: dev@mina.apache.org
Subject: Re: Shutting down a server elegantly

Hi Uday,

On 3/21/07, Uday Prakash (DHL CZ) <ud...@dhl.com> wrote:
> Hi,
>
> I've been working on a small tcp/ip server, that listens for specific
> messages and then depending on the message type performs a particular
> task. That was the easy part, I was looking into shutting down the
> server in an elegant manner. I decided that I'll be listening on a
> particular port say 'SHUTDOWN_PORT' and when I receive a pre-defined
> message to shutdown, I shall shut the server down.
>
> To do so, I call on acceptor.unbindAll() and shutdown the executor
> services. As the documentation points, but what I see is that the
> threads continue to stay alive. Is there something I'm doing wrong?
>
> A little direction would help.

All remaining threads should be daemon threads once the port is
unbound, and therefore the VM should exit automatically.   If the VM
doesn't exit automatically, please capture the full thread dump after
unbindAll() operation, and send it here so we can analyze the cause of
the problem.

HTH,
Trustin
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6


RE: Shutting down a server elegantly

Posted by "Uday Prakash (DHL CZ)" <ud...@dhl.com>.
Hi Trustin,

I guess I spoke before the proverbial chicken hatched!

As requested i am attaching the full thread dump, from what I see the
SocketAcceptor isn't dying for some reason...

Could you let me know what you think.

Thank You,

-Uday

-----Original Message-----
From: Trustin Lee [mailto:trustin@gmail.com] 
Sent: Wednesday, March 21, 2007 4:27 AM
To: dev@mina.apache.org
Subject: Re: Shutting down a server elegantly

Hi Uday,

On 3/21/07, Uday Prakash (DHL CZ) <ud...@dhl.com> wrote:
> Hi,
>
> I've been working on a small tcp/ip server, that listens for specific
> messages and then depending on the message type performs a particular
> task. That was the easy part, I was looking into shutting down the
> server in an elegant manner. I decided that I'll be listening on a
> particular port say 'SHUTDOWN_PORT' and when I receive a pre-defined
> message to shutdown, I shall shut the server down.
>
> To do so, I call on acceptor.unbindAll() and shutdown the executor
> services. As the documentation points, but what I see is that the
> threads continue to stay alive. Is there something I'm doing wrong?
>
> A little direction would help.

All remaining threads should be daemon threads once the port is
unbound, and therefore the VM should exit automatically.   If the VM
doesn't exit automatically, please capture the full thread dump after
unbindAll() operation, and send it here so we can analyze the cause of
the problem.

HTH,
Trustin
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6


Re: Shutting down a server elegantly

Posted by Trustin Lee <tr...@gmail.com>.
Hi Uday,

On 3/21/07, Uday Prakash (DHL CZ) <ud...@dhl.com> wrote:
> Hi,
>
> I've been working on a small tcp/ip server, that listens for specific
> messages and then depending on the message type performs a particular
> task. That was the easy part, I was looking into shutting down the
> server in an elegant manner. I decided that I'll be listening on a
> particular port say 'SHUTDOWN_PORT' and when I receive a pre-defined
> message to shutdown, I shall shut the server down.
>
> To do so, I call on acceptor.unbindAll() and shutdown the executor
> services. As the documentation points, but what I see is that the
> threads continue to stay alive. Is there something I'm doing wrong?
>
> A little direction would help.

All remaining threads should be daemon threads once the port is
unbound, and therefore the VM should exit automatically.   If the VM
doesn't exit automatically, please capture the full thread dump after
unbindAll() operation, and send it here so we can analyze the cause of
the problem.

HTH,
Trustin
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6