java - Does Mysql execute statement synchronously in one connection? -
connection connection = drivermanager.getconnection("jdbc:mysql://localhost:3306/","root", "password");
let's in java, can create mysql connection via code above. connection
object, can create few statement
objects below:
statement = connection.createstatement();
i know, if execute statement
object (by calling statement.executequery
) in different threads, execute synchronously or asynchronously in mysql database? because know is, 1 connection in mysql handled 1 thread, thinking is, statements created connection schedule in queue. correct?
so, if have servlet
below:
public class helloservlet extends httpservlet { connection connection = drivermanager.getconnection("jdbc:mysql://localhost:3306/","root", "password"); public void doget(httpservletrequest request, httpservletresponse response) throws ioexception, servletexception { statement = connection.createstatement(); } }
from code above, if there more 1 user connect servlet
@ same time, block each other because statement cannot execute parallel @ same time? so, have wait previous statement finish executing before turn take on? way avoid kind of problem?
because know is, 1 connection in mysql handled 1 thread, thinking is, statements created connection schedule in queue.
you should not hold database connection open database. should use connection pool apache's dbcp , connection, execute query or other sql, , release connection pool.
if there more 1 user connect servlet @ same time, block each other because statement cannot execute parallel @ same time? so, have wait previous statement finish executing before turn take on?
right. if have 1 user making database transaction, thread cannot use same connection database @ same time.
public class helloservlet extends httpservlet { connection connection = drivermanager.getconnection("j...");
yeah, should not create connection field servlet class this. open tcp connection database , hold life of application. these connections time out or closed because of network issues need kept alive , on occasion reopened. of handled dbcp or other connection pools.
Comments
Post a Comment