I want to create a thread and run the code in this thread. What are the options in Scala?
A usage example would be something like this:
Thread.currentThread setName "MyThread"
val myThreadExecutor = ???
val threadNamePromise = Promise[String]
future {
myThreadExecutor run {
val threadName = "MySpecialThread"
Thread.currentThread setName threadName
threadNamePromise success threadName
}
}
Await.result(threadNamePromise.future, Duration.Inf)
future {
myThreadExecutor run {
println(Thread.currentThread.getName) // MySpecialThread
}
}
future {
myThreadExecutor run {
println(Thread.currentThread.getName) // MySpecialThread
}
}
println(Thread.currentThread.getName) // MyThread
Is there anything in the Scala built-in library that I can use?
Edit
I updated the snippet to better reflect the intention
source
share