Thanks for your insight, JM
Very helpful.
Regards
LongkerDandy
On Wed, Jun 25, 2014 at 11:57 PM, Johan Maasing <johan_at_zoom.nu> wrote:
> 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_at_gmail.com>:
>
> 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
>>
>
>