Asaf Nevo
Asaf Nevo

Reputation: 11678

java multithreading and mysql

I have an application which runs some multi-threading process.
In each thread I'm sharing the same connection to my mysql db which store information important for the thread to run.

Usually when multi-threading I must check for synchronization so I want to share the same resource at the same time, but do I have to do the same with mysql?

I'm using innodb which locks the row when using it, and I don't know if I need to look the access to it in my code too.

To my understanding it doesn't matter if I do it or not because the server it self manage its connection but again I'm not sure.

Upvotes: 2

Views: 4361

Answers (1)

henryabra
henryabra

Reputation: 1443

Connections in java are not guaranteed to be thread safe.

In addition to that, Mysql (and innodb in particular) can handle multiple connections safely.

In a comment to you question (by Emil Vikström), solutions are proposed to your problem;

(Edit) and I quote:

Have you checked out one of the multiple questions dealing with this topic already? For example: Java Threads and MySQL and Is MySQL Connector/JDBC thread safe? – Emil Vikström

Upvotes: 1

Related Questions