最近、以下の例を見ました。メインスレッドとパッセンジャースレッドが同期ブロックに同時に留まる方法を理解できませんか?
public class bus 
{
    public static void main(String[] args) throws InterruptedException 
    {
        passenger p = new passenger();
        p.start();
        synchronized (p) 
        {
            System.out.println("passenger is waiting for the bus, i am in synchronised method");
            p.wait();
            System.out.println("passenger  got notification");
        }
        System.out.println("after "+p.total+" time");
    }
}
class passenger  extends Thread 
{
    int total = 0;
    public void run() 
    {
        synchronized (this) 
        { 
            System.out.println("wait ....  i am in synchronised method");
            for (int i = 0; i <= 1000; i++)
            total = total + i;
            System.out.println("passenger  is given  notification call");
            notify();
        }
    }
} 
このプログラムの出力は
passenger is waiting for the bus i am in synchronised method
wait ....  i am in synchronised method
passenger  is given  notification call
passenger  got notification
after 500500 time
つまり、メインスレッドが「passenger is waiting for the bus i am in synchronized method」と出力したとき、それはすでに同期ブロックに入って待機していたことを意味します。次に表示されるステートメントは、"wait .... i am in synchronized method" です。これは、パッセンジャー スレッドも同期ブロックに入ったということです。同期された両方のブロックが同じオブジェクト (pブロック オブジェクト) を持っていることに注意してください。synchronized(p)メインスレッドがブロックに入ったとき、メインスレッドはオブジェクトをブロックしている必要がpあり、定義により、他のスレッドはオブジェクトの同期ブロックまたはメソッドにアクセスまたは入力できないことを理解しているため、これは紛らわしいようpです!