Emmanuel MacCaull cccf87ba7a Speed up concurrent pool creation
Initializing multiple pools in parallel incurred significant lock
contention on `poolMap` because this lock was held while any `Pool` was
being constructed (which could take several seconds).

Because of this, connecting to independent databases in parallel was not
possible (Pool creation was serialized), severely limiting overall
performance.

*Changes*

* Add `PoolHolder` to defer creation of `Pool` and act as a lock for
  each pool key.
* Insert a new `PoolHolder` while holding the `poolMap` lock, reducing
  global thread contention.
* Threads looking up the same key will acquire the same `PoolHolder` and
  that `PoolHolder` will ensure that only one `Pool` is created. Threads
  looking up unrelated `PoolHolder` will not be blocked by `Pool`
  creation.
* Make registerJxm/unRegisterJmx thread safe. When Pool creation
  happened in parallel, there were errors in the logs because `Pool` was
  attempted to be registered more than one.

*Testing*

This change should have no impact on functionality. Performance should
be improved when creating many Pools in parallel. Performance should
remain the same when creating `Pool` instances sequentially.

* Unit test added to validate that many pools can be created in parallel
  without issue.
* Tested against ~20 real DB servers and saw performance improvement.
  All connections were created at the same time on separate threads.
2025-05-12 12:33:34 -07:00
2025-05-12 12:33:34 -07:00
2015-01-30 14:19:04 +01:00
2025-03-02 16:31:05 +01:00
2024-06-19 14:27:39 +02:00
2025-03-27 11:52:40 +01:00
2013-04-04 18:59:30 +02:00
2025-03-31 19:48:42 +02:00
2025-03-27 01:49:08 +01:00

mariadb logo

MariaDB java connector

MariaDB java connector is a JDBC 4.2 compatible driver, used to connect applications developed in Java to MariaDB and MySQL databases. MariaDB Connector/J is distributed under the LGPL license version 2.1 or later (LGPL-2.1-or-later)

Tracker link https://jira.mariadb.org/projects/CONJ/issues/

Status

Linux Build Maven Central License (LGPL version 2.1) codecov

Obtaining the driver

For java 8+ :

The driver (jar) can be downloaded from mariadb connector download or maven :

<dependency>
	<groupId>org.mariadb.jdbc</groupId>
	<artifactId>mariadb-java-client</artifactId>
	<version>3.5.3</version>
</dependency>

Development snapshot are available on sonatype nexus repository

<repositories>
	<repository>
		<id>sonatype-nexus-snapshots</id>
		<name>Sonatype Nexus Snapshots</name>
		<url>https://oss.sonatype.org/content/repositories/snapshots</url>
	</repository>
</repositories>

<dependencies>
	<dependency>
		<groupId>org.mariadb.jdbc</groupId>
		<artifactId>mariadb-java-client</artifactId>
		<version>3.5.4-SNAPSHOT</version>
	</dependency>
</dependencies>

Documentation

For a Getting started guide, API docs, recipes, etc. see the

Contributors

A big thanks to all contributors

Description
MariaDB Connector/J is used to connect applications developed in Java to MariaDB and MySQL databases. MariaDB Connector/J is LGPL licensed.
Readme LGPL-2.1 26 MiB
Languages
Java 100%