Author Archive
daily 02/27/2009
Posted from Diigo. The rest of my favorite links are here.
Who’s Watching the Watchmen?
After months of being on the reserve list, the library finally let me checkout Watchmen (which is at least as fantastic as you can imagine). I was reading it last night while on the couch with Leah. Leah pointed to the back of the book.
Leah: “Dad, who’s that?”
Me: “That’s Alan Moore. He wrote this book.”
Leah: “He looks funny!“
Me: “I know he does.”
We talked a little more about a few other things, not related to the book, and then Leah said, “That guy on the back of the book? I bet he got a haircut!”
I certainly hope so, but I doubt it.
daily 02/25/2009
Posted from Diigo. The rest of my favorite links are here.
Be careful with DriverManagerDataSource
I needed to populate a lot of development data in a database. I wrote a simple script and configured my DataSource like this:
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName"
value="oracle.jdbc.driver.OracleDriver"/>
<property name="url" value="{URL}"/>
</bean>
Then I fired up my script and let it run.
Soon my phone rang. It was a DBA.
DBA: “Are you connecting to dev007?”
Me: “Yes.”
DBA: “Well, stop it! You have made over 100,000 connections in the last two hours!”
What? Really? Yes, really.
A little research shows that DriverManagerDataSource makes a new connection, does the work, and then closes. Every. Single. Time. No pooling!
Now research shows that SingleConnectionDataSource would have worked nicely for me in this instance, but instead I used Apache’s BasicDataSource.
So then my setup looked something like this:
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
<property name="url" value="{URL}"/>
<property name="poolPreparedStatements"><value>true</value></property>
<property name="maxActive"><value>1</value></property>
<property name="maxIdle"><value>1</value></property>
</bean>
I made the change, started the script, and verified with the DBA that it was not creating a new connection for each insert. If you were using this in a production-type environment (which I wasn’t in this case) you would want more than 1 for maxActive.
daily 02/20/2009
Posted from Diigo. The rest of my favorite links are here.
