Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails Quartz MongoDB connections keep opening

I have a grails app that uses quartz to loop through a domain class every 20 seconds.

Every time the quartz job is executed, another connection is made to Mongo. The previous ones do not close for some reason and so after 11 connections the job stops working (connection timeout). I tried another approach by calling a URL with the service methods being called in the action, but the number of connections still keep rising. When I call the URL repeatedly without the Quartz job running, only 4 new connections are made and no more.

Any ideas how to go about this?

Grails 2.1.2, MongoDB plugin 1.1.0, Quartz 1.0

like image 918
Martin Kontsek Avatar asked Nov 28 '25 05:11

Martin Kontsek


1 Answers

For me it works with the following workaround: wrap your execution code in a [SomeDomain].withNewSession { } call.

Example with User domain

def execute() {
   User.withNewSession {
      //your code
   }
}
like image 59
fabiangebert Avatar answered Nov 30 '25 22:11

fabiangebert



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!