Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Well this solution is not really good. but works.</p> <pre><code>public class FiveSecond { public static void main(String args[]){ new Thread(new Count(new Reader())).start(); } } class Count implements Runnable{ Reader r;Thread t; Robot ro; public Count(Reader t){this.r=t; try { ro=new Robot(); } catch (AWTException e) {e.printStackTrace();} } @Override public void run() { t=new Thread(r); //t.setDaemon(true); //[S2] t.start(); try{ Thread.sleep(5000); }catch(Exception e){} t.interrupt(); //Implicitly press the enter key in order to release the readLine() method :D //not recommended, and it's not a good idea, but works ro.keyPress(KeyEvent.VK_ENTER); ro.keyRelease(KeyEvent.VK_ENTER); /* * this is possible to save the strings lines in somewhere in order to access from invoker application * or send back the strings by socket, etc . . . */ System.out.println("number of entered lines "+r.getCount()+"\n"); //you would run this main as a process and get the number of counts //System.exit(r.getCount()); //[S2] } } class Reader implements Runnable{ private List&lt;String&gt; lines; private volatile int count; private BufferedReader br; public Reader(){ lines=new ArrayList&lt;String&gt;(); br=new BufferedReader(new InputStreamReader(System.in)); } @Override public void run() { try{String line; System.out.println("you have 5 second to detect a 2048 length character, then your system will broken"); while((line=br.readLine())!=null){ if(!Thread.currentThread().isInterrupted()){ count++;lines.add(line);}else{break;} } //for showing the lines entered //System.out.println(lines.toString()); }catch(Exception ex){} } public int getCount(){return this.count;} } </code></pre> <p>but the best approach is about running a separated process to count the lines, and you would just remove the <code>[S2]</code> comments to achieve it.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload