Scala School - Concurrency in Scala
trait Runnable { def run(): Unit } Callable is similar to run except that it returns a value trait Callable[V] { def call(): V } Threads Scala concurrency is built on top of the Java concurrency model. On Sun JVMs, with a IO-heavy workload, we can run tens of thousands of threads on a single machine. A Thread takes a Runnable. You have to call start on a Thread in order for it to run the Runnable. scala> val hello = new Thread(new Runnable { def run() { println("hello world") } }) hello: java.lang.Thread = Thread[Thread-3,5,main] scala> hello.start hello world When you see a class implementing Runnable, you know it's intended to run in a Thread somewhere by somebody. Something single-threaded Here's a code snippet that works but has problems. import java.net.{Socket, ServerSocket} import java.util.concurrent.{Executors, ExecutorService} import java.util.Date class NetworkService(port: Int, poolSize:Read full article from Scala School - Concurrency in Scala
No comments:
Post a Comment