JAVA关于多线程中对象的调用问题

作者: xuzizi 分类: Java 发布时间: 2016-03-22 00:30

JAVA关于多线程中对象的调用问题

public class test {

    public static void main(String[] args) {

        WarnCars car = null;
        car = getCar();

        CarTest test = new CarTest();
        test.setCar(car);
        test.start();

        DataChangeTest testdata = new DataChangeTest();
        testdata.setCar(car);
        testdata.start();

    }

}


public class CarTest extends Thread {
    WarnCars car = null;

    public void setCar(WarnCars car) {
        this.car = car;
    }

    public void run() {
        //do sth
    }

}

public class DataChangeTest extends Thread {

    WarnCars car = null;

    public void run() {
        //do sth
    }

    public void setCar(WarnCars car) {
        this.car = car;
    }
}

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注