java synchronized (this) scope

This question already has an answer here:

  • Avoid synchronized(this) in Java? 18 answers

  • 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.

    链接地址: http://www.djcxy.com/p/76258.html

    上一篇: 同步对象,java

    下一篇: java synchronized(this)作用域