import lombok.Synchronized; public class SynchronizedExample { private final Object myLock = new Object(); @Synchronized public static void hello() { System.out.println("world"); } @Synchronized public int answerToLife() { return 42; } @Synchronized("myLock") public void foo() { System.out.println("bar"); } }