java - Using synchronized/locks in future code -
we building web app scala, play framework, , mongodb (with reactivemongo our driver). application architecture non-blocking end end.
in parts of our code, need access non-thread-safe libraries such scala's parser combinators, scala's reflection etc. enclosing such calls in synchronized
blocks. have 2 questions:
- are there gotchas out when using
synchronized
future-y code? - is better use locks (such
reentrantlock
) rathersynchronized
, both performance , usability standpoint?
this old question)) see here using-actors-instead-of-synchronized example. in short more advisable use actors instead of locks:
class greetingactor extends actor actorlogging { def receive = { case greeting(who) ⇒ log.info("hello " + who) } }
only 1 message processed @ given time, can put not-thread safe code want instead of log.info, work ok. btw using ask pattern can seamlessly integrate actors existing code requires futures.
Comments
Post a Comment