Let's say you have the following class:

```
class A {
    private Foo foo = new Foo();
    Foo getFoo() {
        return foo; //foo.clone()?
    }
    void modifyFoo() {
        //modify this.foo
        //...
    }
}

```

I want to allow:

* either multiple threads to call `getFoo()`
* or one thread to call `modifyFoo()`,
* once a thread wants to modify foo, no other new `getFoo()` calls arriving after that may be executed, until modification is done.

Are there classes already for this problem in Java or do I have to implement it? If I have to implement it, then how do I implement it ensure thread safety?