Keeping wait() calls with in synchronized block closely to adhere
SonarQube rules.
Avoid nested synchronized block by extracting method.
Added writing and reading time to simulate testing to ensure
1) writers are waiting for globalMutex to be empty
2) readers to confirm there is no writers.
resources (Connection, Statement and resultSet) until the stream is
closed by the consumer. So try-with-resources is not an option as per
sonarqube’s recommendation. But it is still recommended to close
statement and result set. When connection pool used, connection is not
closed when close() called. It is just returned to the pool.
Using //NOSONAR to avoid false blocker issue.