So we have 2 thread, one will be printing odd numbers and others will be printing even number. We have to print them in a synchronized fashion. class Lock { Boolean isOdd; Lock(Boolean odd) { this.isOdd = odd; } synchronized void print(Integer number) { Boolean numberEven = number %2 == 0; while (isOdd == numberEven) { try { wait(); } catch( InterruptedException e) { Thread.currentThread().interrupt(); } } System.out.println(number); isOdd = !isOdd; notify(); } } class PrintThread...
Collection of Interview Question on Data structure, Algorithm, Java, C++ and more