package com.example.sync;

public class SynchronizedBlockExample {

	public static void main(String[] args) {

		// create resource
		SharedResource resource = new SharedResource();

		// create workers
		Worker worker1 = new Worker(resource);
		Worker worker2 = new Worker(resource);

		worker1.start();
		worker2.start();

		try {
			worker1.join();
			worker2.join();
		} catch (InterruptedException ex) {

		}

		// with join(), main thread will be blocked here until
		// both worker1 and worker2 completed
		// once join() call completed, main thread will continue from here
		System.out.println("Final counter value: " + resource.getCounter());
	}

}
