object CachedThread {
def main(args: Array[String]): Unit = {
val threads = Executors.newCachedThreadPool
for (i <- 1 to 5) {
threads.execute(new MyThread("cached-thread(" + i + ")"))
}
Thread.sleep(3000)
threads.shutdown
}
class MyThread(name: String) extends Runnable {
override def run() {
for (i <- 1 to 5) {
println(name + ":" + i)
Thread.sleep(10)
}
}
}
}
def main(args: Array[String]): Unit = {
val threads = Executors.newCachedThreadPool
for (i <- 1 to 5) {
threads.execute(new MyThread("cached-thread(" + i + ")"))
}
Thread.sleep(3000)
threads.shutdown
}
class MyThread(name: String) extends Runnable {
override def run() {
for (i <- 1 to 5) {
println(name + ":" + i)
Thread.sleep(10)
}
}
}
}