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:

  1. are there gotchas out when using synchronized future-y code?
  2. is better use locks (such reentrantlock) rather synchronized, 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

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -