Are multithreaded database transactions via connection-pooling threadsafe?

sdo :

Example Scenario:

Using a threadpool in java where each thread gets a new connection from the connectionpool and then all threads proceed to do some db transaction in parallel. For example inserting 100 values into the same table.

Will this somehow mess with the table/database or is it entirely safe without any kind of synchronization required between the threads?


I find it hard to find reliable information about this subject. From what I gather DB engines handle this on their own/if at all (PostgresQL apparently since version 9.X). Are there any well written articles explaining this further?

Bonus question: Is there even a point to make use of parallel transactions when the DB runs on a single hdd?

Ancoron :

As long as the database itself is conforming to ACID you are fine (although every now and then someone finds a bug in some really strange situation).

To the bonus question: for PostgreSQL it totally does make sense as long as you have some time for collecting concurrent transactions (increase value for commit_delay), which then can help combining disk I/O's into batches. There are also other parameters for transaction throughput tuning, most of which can be pretty dangerous if Durability is one of your major concerns.

Also, please keep in mind that the database client also needs to do some work between database calls which, when executed sequentially, will just add idle time for the database. So even here, parallelism helps (as long as you have actual resources for it (CPU, ...).

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=105491&siteId=1