java synchronized (this) scope
This question already has an answer here:
What this means is that more than one threads cannot enter these two synchronized blocks (or one of them) at 'the same time' . Whether it works depends on what exactly you want to achieve.
The thread which is currently in such a synchronized block is said to own the object's monitor at that moment of time (in this case the monitor of the object pointed to by this
).
The threads are synchronized on this
. So only one thread is in the class at the same time (assuming there are no other methods). You are not synchronizing on the methods separately. So this might just work ok. Though it is hard to tell as i have no idea what you want to do in the methods. Concurrency is alway tricky.
上一篇: 同步对象,java