[ACCEPTED]-How to create fair lock to solve starvation in java?-reentrantlock

Accepted answer
Score: 10

Fairness has nothing to do with thread priorities. The javadoc says:

The 9 constructor for this class accepts an optional 8 fairness parameter. When set true, under 7 contention, locks favor granting access 6 to the longest-waiting thread.

On the other 5 hand, thread priorities are hints to the 4 native thread scheduler in order to give 3 more CPU time to high-priority threads than 2 for low-priority threads if they are competing 1 to get CPU time.

Score: 0

I have created a sample implementation using 5 java wait() and notify() framework. Which provides the 4 lock based on first come first serve (FCFS) basis 3 irrespective of thread priority.

You can 2 have a look at the Fair lock implementation 1 at https://github.com/nenapu/JavaLocks

More Related questions