Implement reader - writer problem in java