We are building a web app with Scala, Play framework, and MongoDB (with ReactiveMongo as our driver). The application architecture is non-blocking end to end.
In some parts of our code, we need to access some non-thread-safe libraries such as Scala's parser combinators, Scala's reflection etc. We are currently enclosing such calls in synchronized
blocks. I have two questions:
- Are there any gotchas to look out for when using
synchronized
with future-y code? - Is it better to use locks (such as
ReentrantLock
) rather thansynchronized
, from both performance and usability standpoint?
Future
s. I thought that was sufficiently clear from the context (Play, Reactive* etc), but it seems it wasn't, so apologies.