In Play 2.3 tutorial is is written that
A Controller is nothing more than a singleton object that generates Action values.
And the following example is provided.
package controllers
import play.api.mvc._
object Application extends Controller {
def index = Action {
Ok("It works!")
}
}
Everything is ok and clear with this but I was thinking about concurrency and how exactly this singleton object controller stands from the performance point of view? Can anyone familiar good enough with Play internal architecture explain why should a controller be singleton and how multiple user requests are going through this singleton object?
In Play Design, Action is stateless: it gets a request and raises a result. Controller define Actions that can be called from router (or by chaining from other actions), which still doesn't imply having a state. Being stateless, concurrent can't raise issue accessing shared data (from instance state).
That's why controller can be a singleton/stateless instance (or not, it doesn't bother Play controller being defined as class).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With