Skip to content

Instantly share code, notes, and snippets.

@computereasy
Created December 1, 2016 15:32
Show Gist options
  • Save computereasy/b53e9f55512bf5a077744ff73e8f93c2 to your computer and use it in GitHub Desktop.
Save computereasy/b53e9f55512bf5a077744ff73e8f93c2 to your computer and use it in GitHub Desktop.
Scala thread pool example
import java.util.concurrent.Executors
val pool = java.util.concurrent.Executors.newFixedThreadPool(2)
1 to 10 foreach { x =>
pool.execute(
new Runnable {
def run {
Thread.sleep(2000)
println("n: %s, thread: %s".format(x, Thread.currentThread.getId))
}
}
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment