benefitted from concurrent scheduling ◦ Complexity in code ◦ Overhead in time • Parallel execution on multiple cores will always be more beneficial ◦ It may be complex to do ◦ But it would be an overhead not to do so
for parallel execution ◦ Collection processing ◦ Recursion • Fork-Join model of Java 7 ◦ Recurse task invocation ◦ Without thread starvation (work stealing algo) doTask : collection - if empty return zero - else return head' + doTask tail if (my portion of the work is small enough) do the work directly else split my work into two pieces invoke the two pieces and wait for the results
Usually sporadic ◦ Hard to spot in code ◦ Usually distant from problem • Occurs when ◦ More than one thread ◦ Working on common data ◦ At least one write operation Remove one condition and problem is solved
write data directly • Isolated mutability ◦ Only 1 thread access and write data • Immutability ◦ What is written is unchangeable ◦ By means of final keywords ◦ copy on write collections ◦ Linked Lists, Tries
◦ C)onsistent ◦ I )solated ◦ D)urable • All writes are within a transaction ◦ idempotent ◦ Without side effects • Automatic retry on rollback • Used in some functional languages ◦ e.g. clojure Not necessary
Actor ◦ Has its own message queue ◦ Execute actions sequentially • Calling an actor ◦ Is usually asynchronous ◦ Block for synchronous calls • All actors share a threadpool • Used extensively in Erlang and Scala ◦ Scala have multiple actor libraries ◦ Upcoming examples use akka libraries
receive = { case name : String => self.reply_?(String.format("%s, your future is bright", name)) } } object FortuneTeller { def main(args: Array[String]) : Unit = { val nostradamus = Actor.actorOf[FortuneTeller].start() nostradamus ! "Niels" val response = nostradamus !! "Martin" response match { case Some(responseMessage) => println(responseMessage) case None => println ("Never got a response before timeout") } Actors.registry.shutdownAll } }
become much better with regards to concurrency, but... ◦ STM provide a consistency advantage in large, read intensive data models ◦ Actors break traditional sequential processing and isolates execution via (primarily) asynchronous messages poolsize = number of cores / (1 - blocking coefficient)
the grounds that I don't know the answer" "We have normality. I repeat we have normality. Anything you still cannot cope with is therefore your own problem" He was a dreamer, a thinker, a speculative philosopher..... or, as his wife would have it, an idiot For a moment, nothing happened. Then, after a second or two, nothing continued to happen