Hi all.
I am confused if these two method need to be synchronized.
My initial design is using caching the contractor information into a List<Contractor> object. The class Contractor is just contains 6 fields information(Location, Salary, Stuff...). My scenario is:
Thread a & Thread b is going to access my List<Contractor> object. Say Thread a run like:
When the Thread a gets the writeLock and is updaing the List<Contractor> (Assuming it will take a long time to finish the update procedure), meanwhile, Thread b wants to readRecord or findByCriteria:
Because the ReadWriteLock.writeLock is obtained by the Thread A. So the Thread B has to wait until the Thread A release the ReadWriteLock.writeLock. However, the my assignment said:
Any attempt to lock a resource that is already locked should cause the current thread to give up the CPU, consuming no CPU cycles until the desired resource becomes available.
My questions:
1. Does mean I have failed if I used the above logic to implement the Interface?
2. Do I need to synchronize readRecord & findByCriteria? Is it a servious mistake if I don't synchronize readRecord & findByCriteria?
Regards,
Pkinuk