/** * Initializes a connection to the provided database. */ @Override public synchronized void init() throws SQLException { if (state.type == StateType.ZERO) { state = normalState(); } }
private HikariDataSource checkAndGetDataSourcePool() throws SQLException { while (true) { // Volatile read state to see if we can get through here without locking. State stateLocal = state; switch (stateLocal.type) { case ZERO: // Not yet initialized, no such luck. synchronized (this) { if (state == stateLocal) { // The state hasn't changed on us, we can perform // the initialization and start over again. state = normalState(); } else { // Someone else changed the state on us, just start over. } } break; case NORMAL: // Normal state, good to go return stateLocal.dataSourcePool; case CLOSED: throw new SQLException("Hikari connection pool already closed!", stateLocal.closeTrace); } // fall throughs are spins } }
/** * Initializes a connection to the provided database. */ @Override public synchronized void init() throws SQLException { if (state.type == StateType.ZERO) { state = normalState(); } }
private HikariDataSource checkAndGetDataSourcePool() throws SQLException { while (true) { // Volatile read state to see if we can get through here without locking. State stateLocal = state; switch (stateLocal.type) { case ZERO: // Not yet initialized, no such luck. synchronized (this) { if (state == stateLocal) { // The state hasn't changed on us, we can perform // the initialization and start over again. state = normalState(); } else { // Someone else changed the state on us, just start over. } } break; case NORMAL: // Normal state, good to go return stateLocal.dataSourcePool; case CLOSED: throw new SQLException("Hikari connection pool already closed!", stateLocal.closeTrace); } // fall throughs are spins } }