How to stop a thread,which is scanning from standard input stream, by using another thread?
<p>I have a thread in which data is scanning from standard input stream as:</p>

<pre><code>1. Scanner scan = new Scanner(System.in);
2. while(true)
3. {
4.   String str = scan.nextLine();
5.   System.out.println(str);
6. }
</code></pre>

<p>I want to stop this thread by another thread. I heard it is not good to use Thread.stop(). Using some boolean flag also will not solve it as the pointer (program execution step) will be always at line 4. String str = scan.nextLine();</p>

<p>Is there any way that I can stop the thread?</p>
