【scala】無ロックマルチスレッド印刷1->100
768 ワード
import java.util.concurrent.atomic.AtomicInteger
import scala.concurrent.{ExecutionContext, Future}
object ThreadTest {
def main(args: Array[String]): Unit = {
val i = new AtomicInteger(1)
def createF(threadContext: Int)(implicit executionContext: ExecutionContext) = Future{
val v = i.get()
var tag = true
for (j if(b) thread2 else Future.successful(false))
def thread2: Future[Boolean] = createF(2)
.flatMap(b => if(b) thread3 else Future.successful(false))
def thread3: Future[Boolean] = createF(3)
.flatMap(b => if(b) thread1 else Future.successful(false))
thread1
while(true) 1
}
}