用线程改变变量的值

时间:2015-09-27 12:01:09

标签: java multithreading

我编写了用线程更改某个对象的成员变量的程序,但是当我想打印该变量时,它会打印旧值。我试过调试,它工作正常。任何建议,我都不明白是什么问题。

public class Auction   {
private volatile int currentBid;
public Auction(int currentBid){
    this.currentBid=currentBid;
}
public int getCurrentBid(){
    return this.currentBid;
}
public synchronized void changeBid(int value){
    this.currentBid+=value;
}


Public class User {
  private String name,
  private int age,
public User(String name,int age){
    this.name=name;
    this.age=age;
}
public void changeBid(Auction auction, int changeValue){
    Thread thread=new Thread(new Bid(auction,changeValue));
    thread.start();
}

0 个答案:

没有答案