Exchange of connections between multiple streams is typically accomplished using a connection pool. Each thread can request a connection from the pool, use it for its own purposes (one or more transactions, complete or roll back) and return it to the pool after the task is completed.
This is what application servers offer you. They will also take care of transactions. e. when the method that requested the transaction ends normally, changes are made, if it throws an exception, the database transaction is rolled back.
I suggest you take a look at Java EE 5 or 6 - it is very easy to use and can even be used on embedded systems. For an easy start, take a look at Netbeans and the Glassfish application server. However, the general concepts apply to all application servers.
As for InnoDB, it will not have problems handling a large number of transactions. Under the supervision of the application server, you can focus on business logic and not worry about half-written updates, or anyone who sees updates / inserts before the transaction from which they originate has been completed.
InnoDB uses MVCC (multi version concurrency control), effectively presenting each transaction with a snapshot of the entire database since it was launched. You can learn more about MVCC here in the related question: Question 812512
Daniel Schneller
source share