title: Synchronization in java-- new ReentrantLock(true) and new ReentrantLock(false) producing the same result?
body: <p><strong>ReentrantLock</strong> provides <code>boolean fair</code> flag while creating a Lock object.</p>
  <ol>
  <li><p><code>fair</code>:<code>true</code></p>
  <p>Threads are given access to  critical section based on the time they have been waiting.</p>
  </li>
  <li><p><code>fair</code>:<code>false</code></p>
  <p>There is no specific policy for giving critical section to the threads.</p>
  </li>
  </ol>
  <p>Below is my code for the same:</p>
  <pre><code>public class ThreadDemo {
      private Lock lock = new ReentrantLock(false);
  
      public static void main(String[] args) {
          ThreadDemo td = new ThreadDemo();
          Thread[] tArr = new Thread[5];
          // Creates 5 thread and stores them in a array
          for (int i = 0; i &lt; 5; i++) {
              tArr[i] = new Thread(() -&gt; {
                  td.enterCriticalSection(new Date().getTime());
              }, &quot;Thread &quot; + i);
          }
          // Iterate through the array and start it.
          for (int i = 0; i &lt; 5; i++) {
              tArr[i].start();
              try {
                  Thread.currentThread().sleep(1000);
              } catch (InterruptedException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
  
          }
      }
  
      public void enterCriticalSection(long waitTime) {
          System.out.println(Thread.currentThread().getName() + &quot; requesting critical section at:&quot;
                  + new SimpleDateFormat(&quot;HH:mm:ss:SSS&quot;).format(new Date().getTime()));
          // Gets Lock
          lock.lock();
  
          try {
              /*
               * Logs the entry time in critical section and waiting period for
               * the thread
               */
              System.out.println(Thread.currentThread().getName() + &quot; in critical section at  &quot;
                      + new SimpleDateFormat(&quot;HH:mm:ss:SSS&quot;).format(new Date().getTime()));
              Thread.currentThread().sleep(5000);
          } catch (InterruptedException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          } finally {
              // Releases lock
              lock.unlock();
          }
              
          }
  }
  </code></pre>
  <p>But for both <em><strong>fair as true</strong></em> and <em><strong>fair as false</strong></em> i am getting the same result i.e the thread which waits for the longest period gets the critical section</p>
  <pre><code>Thread 0 requesting critical section at:01:57:48:562
  Thread 0 in critical section at  01:57:48:563
  Thread 1 requesting critical section at:01:57:49:520
  Thread 2 requesting critical section at:01:57:50:520
  Thread 3 requesting critical section at:01:57:51:520
  Thread 4 requesting critical section at:01:57:52:520
  Thread 1 in critical section at  01:57:53:564
  Thread 2 in critical section at  01:57:58:564
  Thread 3 in critical section at  01:58:03:565
  Thread 4 in critical section at  01:58:08:566
  </code></pre>