阅读背景:

主线程如何在此线程之前运行?

来源:互联网 

I have the following code:

我有以下代码:

    public class Derived implements Runnable {
        private int num;

        public synchronized void setA(int num) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
            }
            System.out.println("Setting value " + Thread.currentThread().getName());
            this.num = num;
        }

    @Override
    public void run()
    {
        System.out.println("In run: " + Thread.currentThread().getName());
        setA(20);
    }

        public static void main(String[] args) {
            Derived obj = new Derived();
            Thread t1 = new Thread(obj);
            t1.start();
            obj.setA(32);
        }
    }
    publ



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: