I am curious about developing a back-end using the Play Framework in Scala. I’ve only tried the tutorial so far. I was wondering, is it possible to have the different responding “threads” exchange data?
For instance, a counter that counts every time that an HTTP request has been handled. It begins at 0. Then the first request comes in and it becomes 1. At the time of the second requests, the handling “thread” can access that counter somewhere?
This should be achieved without any I/O (files, DB). In Java, it would smell like a static variable, but in Scala? Thank you.
To use a Java static approach take a look at the bellow.
Otherwise maybe you can make use of the Cache (Both Java and Scala)
http://www.playframework.org/documentation/2.0.4/ScalaCache
You can use the a comapnion Object where all you variables will be static.
A Scala worksheet to demonstrate: