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

后端 未结 4 1156
独厮守ぢ
独厮守ぢ 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:14

    public class T1 implements Runnable {
        //parameter of thread T1
        public static AtomicBoolean flag = new AtomicBoolean();
    
        @Override
        public void run() { 
        }   
    }
    
    public class T2 implements Runnable {
    
        @Override
        public void run() { 
            //parameter to an already running thread
            T1.flag.set(true);
        }   
    }
    

提交回复
热议问题