0

I wrote program that changes member variable of some object with thread, but when I want to print that variable, it prints old value. I have tried debugging, it works correctly. Any suggestions, i do not understand what is wrong.

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();
}
Andy
  • 1
  • 1
  • 3
    so where is your code? – SatyaTNV Sep 27 '15 at 12:01
  • Missing the [`volatile` keyword](https://docs.oracle.com/javase/tutorial/essential/concurrency/atomic.html), huh? – Sergey Kalinichenko Sep 27 '15 at 12:03
  • @Andy : Please make object read or write code block `Syncronized` and variable you want to use as `volatile`..!! – Kruti Patel Sep 27 '15 at 12:06
  • 1
    Please [edit your question](http://stackoverflow.com/posts/32807668/edit) to include the code instead of spamming the comments section with code. – Spikatrix Sep 27 '15 at 12:28
  • 2
    there is no way to answer you question. if you do want your question to be solved, you have to review your question in a objective manner to make sure it is solvable, instead of clicking the button and close the browser. – Jason Hu Sep 27 '15 at 12:32

0 Answers0