java.lang.IllegalThreadStateException

后端 未结 5 1526
鱼传尺愫
鱼传尺愫 2020-12-29 19:01

I am working with threads. However when I try to start a thread, I get a Exception. In concrete java.lang.IllegalThreadStateException. My code is:

public voi         


        
5条回答
  •  無奈伤痛
    2020-12-29 19:34

    You are storing the thread in a field. If the method is called in two threads, the readThread.start() can be called twice for the same thread. You need to ensure readCommand is not called multiple times and perhaps not start the readThread again if its already running. e.g. you can synchronized the method and check readThread before you start.

提交回复
热议问题