jeudi 11 janvier 2018

How to provide concurrency control to global variables in java?

If I have one global variable in a java class and I am running many threads, then threads may compete for that variable resulting in unconcurrent values. As far as I know semaphores and mutex can be used for such case, but are there any other approaches that can be used? (I am talking from the design aspect)

Code example:

public class Foo {

    int var1;

    void func1 () {
         var1 = 5;
    }
}

Aucun commentaire:

Enregistrer un commentaire