java - Time of connection to DB using JDBC -
When I check the time run like this, my machine time is But when I test it using my run time, then I do not understand why more time in the job? 735
< / P> public class testdcp {static {try {class.forName ("com.mysql.jdbc.Driver"); } Catch (Clasnostfundai Express E) {// To-O Auto-Generated Catch Block e.printStackTrace (); }} Public static zero main (string [] args) {long l = System.currentTimeMillis (); Connection Conn = Null; {For (ii = 0; i & lt; 100; i ++) {conn = DriverManager.getConnection ("jdbc: mysql: // localhost: 3306 / jdbcdemo", "root", "sph815 @ cs") try; Conn.close (); }} Catch (eclipse e) {// Tudo auto-generated cal block e.printstaxtress (); } System.out.println (System.currentTimeMillis () - l); }}
public class testDBCP {static {try {class.forName ("com.mysql.jdbc.Driver"); } Catch (Clasnostfundai Express E) {// To-O Auto-Generated Catch Block e.printStackTrace (); }} Public static zero main (string [] args) {long l = System.currentTimeMillis (); {For int i = 0; I & lt; 100; I ++} {Try DriverManager.getConnection ("jdbc: mysql: // localhost: 3306 / jdbcdemo", "root", "sph815 @ cs"); }} Catch (eclipse e) {// Tudo auto-generated cal block e.printstaxtress (); } System.out.println (System.currentTimeMillis () - l); }}
You are assuming that execute an additional statement (which is the connection to Closes) means that the program will take longer because execution of close () statements adds additional CPU usage.
If you do not execute it, you can save this CPU time, although the database is handled more, which can degrade its performance, so to run the getConnection () statement It will take more time to execute as the number of open connections.
This is probably the reason why your second version performs at a slow pace from the beginning.
Comments
Post a Comment