Search:

Type: Posts; User: Chris.Brown.SPE

Search: Search took 0.20 seconds.

  1. Re: How to synchronised a variable in a class such that the variable will remain each time a thread is run

    Make a static setter for numOfball

    Example:


    public static void main(String[] args) {

    Book.setTitle("Test");
    }
  2. Re: How to synchronised a variable in a class such that the variable will remain each time a thread is run

    You are setting your static variable in the constructor. This is wrong unless you have some sort of justification for it. Can you confirm you understand this error?
  3. Re: How to synchronised a variable in a class such that the variable will remain each time a thread is run

    This is definitely because you are setting the numOfballs in your constructor for Ball. You are resetting it to 10 with every object. It should be set once at the beginning of the program.
  4. Re: How to synchronised a variable in a class such that the variable will remain each time a thread is run

    The problem is that you're setting the value of numOfBall in your constructor for the Ball class. This is going to reset your static variable each time. You really shouldn't set the value of static...
Results 1 to 4 of 4