Java: how to abort a thread reading from System.in

前端 未结 6 2072
梦谈多话
梦谈多话 2020-12-01 14:35

I have a Java thread:

class MyThread extends Thread {
  @Override
  public void run() {
    BufferedReader stdin =
        new BufferedReader(new InputStream         


        
6条回答
  •  猫巷女王i
    2020-12-01 15:17

    My first reaction is that a thread and System.in really don't go together.

    So first, split this so that the thread code does not touch any static including System.in.

    A thread reads from InputStream and passes into a buffer. Pass an InputStream into your existing thread that reads from the buffer but also checks that you haven't aborted.

提交回复
热议问题