What happens when we use loop instead of while(true) with scala actors? -


what's difference of using loop instead of while(true) while using receive actors. loop seems work faster, why, , what's going on under bonnet?

is there bad use loop instead of while(true)?

more context. i'm doing performance tests within simple ping/pong code. , i'm using receive.

this ping class:

class receiveping(         count : int,         pong : actor        ) extends actor {def act() { var pingsleft = count - 1 pong ! start pong ! receiveping while(true) {   receive {     case receivepong =>       if (pingsleft % 10000 == 0)         console.println("receiveping: pong")       if (pingsleft > 0) {         pong ! receiveping         pingsleft -= 1       } else {         console.println("receiveping: stop")         pong ! stop         exit()       }   } }}} 

instead of while(true) performs better loop.

thanks

using loop releases thread other tasks, while while doesn't. so, if using many actors, use of loop makes more efficient. on other hand, single actor using while , receive faster 1 using loop , react (or, matter, loop , receive).


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -