PHP vs Java MySQL connection pooling -


i have problem thought break down simplest. there 2 applications on lamp stack, 1 php , java , same thing: run simple query:

select * test 

php execution takes 30 ms in total

java excution takes 230 ms in total

query run on local mysql client takes 10-15 ms in total

java takes ~200 ms every time establish connection db. understand php uses kind of built in connection pooling, therefor doesn't need establish new connection every time , takes 30 ms result of it.

is same thing possible on java? far failed achieve that. tried use apache commons dbcp connection pooling, no change @ all, still takes same time connect database.

update: separate question i'm trying make connection pooling work on java, asking code example: java mysql connetion pool not working

you misunderstanding concept , purpose of connection pooling.

connection pooling meant maintain (set of) connections on single (java virtual) machine (typically, application server). goal allow multiple threads on same machine share connection database server without need open 1 everytime need query database.

stand-alone applications cannot share connections run on different java virtual machines, or perhaps on different physical machines.

connection pooling in stand-alone application if had several threads making concurrent access database.

however, can still measure benefit of connection pooling wrapping test (the code inside try...catch) in loop , iterating few times. @ first iteration, connection needs opened. don't forget release connection (call con.close()), reused @ next iteration.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -