I've got a groovy script that I'm running from an event listener.
The script starts a new thread like this:
Thread thread = Thread.start {
try {
def workAttributeValue = null
while (workAttributeValue == null) {
ServiceOutcomeImpl serviceOutcome = workAttributeValueService.getWorkAttributeValueByWorklogAndWorkAttribute(issueEvent.worklog.id, workAttribute.getId())
workAttributeValue = serviceOutcome.getReturnedValue()
}
//does something more with the returned workAttributeValue
} catch (Exception e) {
Thread.currentThread().interrupt()
log.warn("\nLogFlexTime has had an exception " + e.message + "\n" + e)
return
}
return
}
The script starts and finishes before the thread finishes. This is just as espected.
The issue is that the call to workAttributeValueService creates a connection to the DB and in some cases never releases it. Or at least holds on to it for a very long time. The result is that the connection pool goes through the roof and starts to throw exceptions.
So my question is what am I doing wrong here? Am I not closing the Thread or something?