Re: Keep server running without using System.in.read()

  • From: Johan Maasing <johan@...>
  • To: users@...
  • Subject: Re: Keep server running without using System.in.read()
  • Date: Wed, 25 Jun 2014 17:57:28 +0200

Well, you should ask yourself, how do I want to manage the server (i.e.
send it a 'stop' command)?
One way is to use System.in as in the example. Another way I have used is
something like:

this.transport.bind...
final AtomicBoolean keepRunning = new AtomicBoolean(true) ;
while (keepRunning.get()) {
   try {
      Thread.sleep(5000) ;
   } catch (InterruptedException e) {
      keepRunning.set(false) ;
   }
}

Then expose a method through JMX that sets the 'keepRunning' to false.
Which means I can for example start JConsole, attach to the server JVM and
invoke my stop method from JConsole.

Cheers,
JM


2014-06-25 16:45 GMT+02:00 LongkerDandy <longkerdandy@...>:

> Hi
>
>
> I've a TCP Server based on Grizzly, and I followed the examples start the
> server with codes like:
>
>             this.transport.bind(this.host, this.port);
>             this.transport.start();
>             System.in.read();
>
> I wondered if there is a better way to keep the thread runing without
> using System.in.read().
> It doesn't seem to be a elegant way for this job, and easily run into
> trouble with carefuless mistake.
>
> Regards
> LongkerDandy
>


Keep server running without using System.in.read()

LongkerDandy 06/25/2014

Re: Keep server running without using System.in.read()

Johan Maasing 06/25/2014

Re: Keep server running without using System.in.read()

LongkerDandy 06/27/2014

Re: Keep server running without using System.in.read()

Alex Davies-Moore 06/27/2014
Terms of Use; Privacy Policy; Copyright ©2013-2016 (revision 20160708.bf2ac18)
 
 
Close
loading
Please Confirm
Close