Archive | java
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.
How do you cry out against your frustrations?
It seems that every group I work with seems to evolve a special key phrase that let’s us vent our frustrations yet maintain humor to lighten the mood.
Example #1
I worked techical support for a fairly involved software application — clients on different platforms and a central server running SCO Unix (!!!) in the middle. One particular client has their Unix Admin as the technical contact, but they really knew nothing about Unix. It was amazing. They were nice people though, and rarely called, but when they did . . . oh boy.
We were forcing an upgrade and they wanted us to step them through it over the phone. Yes, this was before web meetings where we could have done it for them. The tech lucky enough to get this task (not me!) was an interesting guy. He was great on the phone with the customer, but after he was done you never knew what would come out of his mouth.
Needless to say, this upgrade should have taken an hour and four hours later he’s still on the phone with them. We know they aren’t following our instructions, yet how do you let the customer know that? Once we get them to realize they aren’t doing what we are saying, it goes smoothly. When he is done, he thanks our customer for their patience, hangs up the phone, and screams out so everyone hears,”For the Love of God!“ Hence our catchphrase was born. After that, whenever we were frustrated by something our servers or customers were doing, you would hear someone say, “For the Love of God!”.
Example #2
A few weeks ago our new project manager and I were talking about the current state of our projects and, really, it’s not good. He suddenly cried out: “By the Eye of Thundera!” And I cracked up. It has been a long time since I had heard a Thundercats reference. As the days went by we both muttered that phrase back and forth.
I was gone on Friday, but this Monday morning I had an email from him with the subject line of “grrrr…”. When I opened it, I almost fell on the floor laughing at the picture that greeted me.
So another phrase is born.
I wonder if this is normal for most IT shops? I think so. ”And there was much rejoicing” is a very common phrase in a lot of places. Where I worked in college we said “broked” a lot. Does anyone have any other catch-phrase?
Another TDD Convert
This has been one of the craziest weeks in my IT career, but perhaps one good thing has become of it.
Before and after I became Tech Lead, I’ve been trying to convince everyone that Test-driven Development is really The Way. But I still heard things like, “I have the the code done, now I have to write the tests.” So, really, my message wasn’t getting through.
This week was Panic Mode in a big way. Long story, but me and another guy worked all day and three to four hours at night, and an offshore resource worked all our night (his day) and three or four hours in his night. I’m not saying that it was a job well done nor that I relished it, but one good thing came out of it . . . On Thursday, my on-shore cohort said, “You know, Mike, writing the tests first is really a good thing! Now I know that my code works every time!” And we demonstrated problems with each others logic via unit tests and then we knew what to fix.
He told me this several times during the day, but I knew he was a True Believer when I heard him tell our off-shore guy, “Yeah, I know you fixed it, but you didn’t make any Junits for it.”
Now he sounds like me!
It Makes Me A Jolly Good Fellow
The title makes no sense if you don’t know the wonderful Tom T. Hall song.
So, yes, I like beer.
This summer I have found several new favorites. It helps that the nearby grocery store has variety packs and you can make your own pack! That’s right! They have singles of microbrews and you can assemble your own 6-pack of what you want.
These are the favorites of the summer:
- 90 Schilling from O’Dell Brewing Company is becoming a house favorite. I can’t quite explain it to you, but it’s very smooth and refreshing. It’s really great anytime.
- Point Special Lager from Stevens Point Brewery was my first intro into their beers. It’s an American version of a classic German lager. Even it you don’t like German beer you will like this one.
- Point Belgian White from Stevens Point Brewery is also very good. A very classic Belgian White with a bit of citrus.
- Milk Stout from Left Hand Brewery (gratuitous Flash warning) wasn’t my first foray into a brew from Left Hand. The first beer of theirs was too hoppy for my taste (different than most beer drinkers, I really don’t like strong hops). But this one is probably the best Stout I’ve ever had. Gina also enjoyed the one sip I allowed her to have and she doesn’t generally like stouts at all! It’s very smooth and, well, milky. Sorta like a Coffee Milk Chocolate, only more like beer. Whatever — it’s good!
So there are my new brews of the summer. Happy drinking!
Digging Yourself Into the Circular Injection Hole
Late last week I had to do some major refactoring. One of the things I needed to add was some Spring injection from SomeClass1 into SomeClass2. No big deal — I do this all the time. But after I did that, Spring would error out, saying that there was a circular injection.
This circular injection was not something we did on purpose, but instead was something that evolved. We have functionality in SomeClass1 that we needed in SomeClass3, so we just injected that whole object into SomeClass3. The problem was that SomeClass3 was injected into SomeClass2. Then, when I tried my injection above, Spring rightfully said, “Uh, sorry, I can’t do that.” So I ended up spending a few days taking two large bits of functionality out of SomeClass1 and put them each into separate classes to be injected everywhere we needed them to be. Their injection was kept to a minimum, of course. Then inject these classes into the places that needed them, and run all the unit tests to make sure everything is still okay. Only after all that could we continue.
Why didn’t we do this in the first place? Because we took the fast and easy way of just injecting our classes every-which-way and then getting bit when we least expected it. I mean, the SomeClass1 was really called “XXHandler”!! Injecting a handler class should have told us we were wrong!
So, never again. I want small, simple classes that I can inject into other classes without fear.
