Monday, October 18, 2010

Service and DB connection pools

(From Kwang Ho-Lee's investigations)

When using a Grails service that is transactional (default) and it uses the DB, the service will try and get a connection to the DB from the pool each time it is called.
So it is a bad idea to have code in a controller that calls a service in a loop. The loop should really be in the service, this will prevent multiple connections being made, plus it makes better design sense.

Wednesday, October 13, 2010

Time durations

Some code that shows durations and works nicely as a timer
    import groovy.time.*

    def timeStart = new Date()
    // Some code you want to time
    def timeStop = new Date()
    TimeDuration duration = TimeCategory.minus(timeStop, timeStart)
    println duration
This will give you the time in hours, minutes, seconds