Nate's Programming Blog

Well it has been several months off and on, but I’ve managed to finally get the application that I’ve written at work completely converted to Spring. James Estes turned me on to the inversion of control framework several months ago and I’ve been using it ever since. The last piece that I just converted was a java batch application that scans flat files and calculates invoices and balances from the data. It has 2 possible entry points, one is from the command line where you can specify the location of a service context. The reason I require this at the command line is so that the user of the batch application can specify the location of the base path where the flat files will be stored, this is set as a dependency for one of the service classes. The other required argument is the location of the database context where you define the datasource that will be used. The application as of now has a dependency on an oracle datasource in order to use the oracle drivers to increase performance, but the oracle implementation is hidden behind a dao interface layer, so it would be easy to add another database implementation if necessary. So basically in the database context you just define the connection information. I made this configurable through command line arguments because the 2nd entry point is from a web container and in that situation the datasource would probably already be defined. The web container implementation is the current way that I’m executing the batch. I wire the batch part of the application to the rest of the application using Spring and use a batch scheduler that James Estes wrote and I modified to execute the batch at a defined time.

The old way I had the batch used a single connection for the entire batch process. Not the best of solutions, but I was having a hard time coming up with a transaction implementation and I was short on time. Since I converted to Spring I can now use their light weight container transaction manager proxy to implement a container managed solution to transactions. It works great and I’m much happier with it.

The old way used several singletons for cache prepared statements and connections to increase performance. With the old style I was processing a 1000 line flat file in about 37 seconds on my local computer. You have to take into consideration that the database I was connecting to is about 3 states away, so when it goes to production that number will be much lower. Since converting to Spring I have been able to reduce the time to 35 seconds isn’t a big difference, but I was expecting it to perform worse. I used the jdbc template stuff from Spring for the first time and I’m extremely pleased with it. I was able to reduce code and increase performance with the added overhead of transactions and the whole application context.

Well anyway, Spring is wonderful and I’ll never go back, atleast until something better comes out.


Name (required)

Email (required)

Website

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Feel free to leave a comment

top