user404345
user404345

Reputation:

Grails singleton scoped controller and request object

I understand that grails 2 now supports singleton scoped controllers. I have a requirement to use such a controller and I have a question about the request object (and other implicit objects)

The grails documentation always refers to the request object as an instance variable but in a singleton scoped controller it would not be safe to use such an object. What is the recommended way to handle the implicit objects in a singleton scoped controller? I tried modifying the controller's action signature to accept the request object as a parameter (similar to standard spring MVC) and this appears to work:

class MyController {
  static scope = "singleton"

  def list(request) {
   // do something  
  }
}

However I've also noticed that this.request still exists, so how can I be sure that the parameter request is not just a reference to this.request?

Upvotes: 1

Views: 1037

Answers (1)

Lauri Piispanen
Lauri Piispanen

Reputation: 2097

In either case it would not matter. The request object is bound using a ThreadLocal variable, so it would in all cases be safe to access concurrently.

Upvotes: 3

Related Questions