class Puffer { //Only one thread can access the synchronized method at a time public synchronized void criticalSection(){ Thread current = Thread.currentThread(); System.out.println("Enter the critical section: " + current.getName()); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("Leave the critical section: " + current.getName()); } } class MyRunnable implements Runnable { private Puffer puffer; public MyRunnable(Puffer puffer) { super(); this.puffer = puffer; } @Override public void run() { puffer.criticalSection(); } } public class SynchronizedMain { public static final int N = 10; public static void main(String[] args) { Puffer puffer = new Puffer(); for(int i=0; i