Using Scala, JodaTime, and Squeryl for ORM. There's an annoying problem where once the application starts up, a Timestamp generated using JodaTime doesn't re-initialize every time it's called. Instead it sets the time once and annoyingly doesn't re-initialize every time the SQL is called.
Code below. First, the time parameter:
val todayEnd = new Timestamp(new DateMidnight(now, DateTimeZone.forID("America/Los_Angeles")).plusDays(1).getMillis())
And the Squeryl JOIN:
join(DB.jobs, DB.clients.leftOuter, DB.projects.leftOuter)((j,c,p) =>
where((j.teamId === teamId)
and (j.startTime < todayEnd)
and (j.userId isNotNull)
and (j.canceled === false)
and (j.completed === false))
select(j,c,p)
on(j.clientId === c.map(_.id), j.projectId === p.map(_.id)))
The strange part is that if I generate the todayEnd
timestamp without JodaTime, then it re-initializes every time. So what is JodaTime doing differently?
Found the problem: apparently the thread managing the JOIN was never successfully being shutdown, and was being re-referenced inside Akka. This meant that the todayEnd
variable had never been re-initialized.
So the take-home lesson is: manage your threads.
As I have further learned, the original object holding the time values were set as val
. As it turns out, they need to be def
.
Bad:
val today = new Date()
lazy val today = new Date()
Good:
def today = new Date()