class Sync { public static void main(String[] args) throws InterruptedException { Sync s = new Sync(); Thread t1 = new Thread(() -> s.f()); Thread t2 = new Thread(() -> s.g()); t1.start(); Thread.sleep(1 * 1000); t2.start(); t1.join(); t2.join(); } synchronized void f() { System.out.println("I'm in f"); try { Thread.sleep(10 * 1000); // 10 secs } catch (InterruptedException e) { } } synchronized void g() { System.out.println("I'm in g"); } }