java - Running scanner while getting input from other sources -


currently i'm working on console application in java. i'm trying handle commands scanner while console gets input outside (netty information).

my scanner looks this:

public class commandhandler implements runnable {     private scanner scanner = null;     public void newscanner(){        if(scanner != null) {            scanner.close();            scanner = null;        }         scanner = new scanner(system.in);        system.out.println(scanner.next());        scanner.close();        scanner = null;        newscanner();    }     @override    public void run() {        newscanner();    } } 

i'm running scanner in new thread executorservice:

thread commandhandler = new thread(new commandhandler()); executorservice.execute(commandhandler); 

(1) works fine. input netty , can type in commands. if @ same time, console puts input , input me so:

this test[11:31:52/information] >> client 'lobby-01' connected. [127.0.0.1:8001] 

how can prevent that? input netty prints not gets command.

(2) , if typed in command following error:

this new test exception in thread "pool-1-thread-2" java.util.nosuchelementexception     @ java.util.scanner.throwfor(unknown source)     @ java.util.scanner.next(unknown source)     @ de.zettee.devcloud.master.console.handler.commandhandler.newscanner(commandhandler.java:16)     @ de.zettee.devcloud.master.console.handler.commandhandler.newscanner(commandhandler.java:19)     @ de.zettee.devcloud.master.console.handler.commandhandler.run(commandhandler.java:24)     @ java.lang.thread.run(unknown source)     @ java.util.concurrent.threadpoolexecutor.runworker(unknown source)     @ java.util.concurrent.threadpoolexecutor$worker.run(unknown source)     @ java.lang.thread.run(unknown source) 

i hope can me these 2 problems. :) in advance!


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -