How to pass parameter to an already running thread in java?

后端 未结 4 1144
独厮守ぢ
独厮守ぢ 2021-01-02 18:49

How to pass parameter to an already running thread in java -- not in the constructor, & probably without using wait() (possible ??)

Something similar to a comme

4条回答
  •  执念已碎
    2021-01-02 19:35

    The "other thread" will have its own life, so you can't really communicate with it / pass parameters to it, unless it actively reads what you gives to it.

    A thread which you allows you to communicate with it typically reads data from some buffered queue.

    Have a look at ArrayBlockingQueue for instance, and read up on the Consumer-Producer pattern.

提交回复
热议问题