While running through a piece of code for performance tuning, i noticed that the pooled database connection is not used immediately, it follows some pre-processing before the connection used to delegate a SQL update call.
I fixed the codes by delaying the retrieval of the pooled database connection until before the codes is ready to call on the insert method.
As i am trying to update the documentation that this optimization is done, how should i work it in a sentence or title?
Old Codes:
...
connection = ConnectionFactory.getPooledConnection(); // get pooled connection
String message = StringUtils.replace(log, "a", "b");
// many other processing
connection.update(message);
connection.release();
...
New Codes:
...
String message = StringUtils.replace(log, "a", "b");
// many other processing
connection = ConnectionFactory.getPooledConnection(); // get pooled connection
connection.update(message);
connection.release();
...
Not sure this case actually warrants it - because you've made the code behave more like it "should". But generally, such deferral of work until the moment it is needed is referred to as "lazy initialization".
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.