src/Pure/Concurrent/standard_thread.scala
changeset 62056 6dbeafce6318
parent 61563 91c3aedbfc5e
child 62263 2c76c66897fc
equal deleted inserted replaced
62054:cff7114e4572 62056:6dbeafce6318
     7 
     7 
     8 package isabelle
     8 package isabelle
     9 
     9 
    10 
    10 
    11 import java.lang.Thread
    11 import java.lang.Thread
    12 import java.util.concurrent.{ThreadPoolExecutor, TimeUnit, LinkedBlockingQueue}
    12 import java.util.concurrent.{ThreadPoolExecutor, TimeUnit, LinkedBlockingQueue, ThreadFactory}
    13 
    13 
    14 import scala.concurrent.{ExecutionContext, ExecutionContextExecutor}
    14 import scala.concurrent.{ExecutionContext, ExecutionContextExecutor}
    15 
    15 
    16 
    16 
    17 object Standard_Thread
    17 object Standard_Thread
    33 
    33 
    34   lazy val pool: ThreadPoolExecutor =
    34   lazy val pool: ThreadPoolExecutor =
    35     {
    35     {
    36       val m = Properties.Value.Int.unapply(System.getProperty("isabelle.threads", "0")) getOrElse 0
    36       val m = Properties.Value.Int.unapply(System.getProperty("isabelle.threads", "0")) getOrElse 0
    37       val n = if (m > 0) m else (Runtime.getRuntime.availableProcessors max 1) min 8
    37       val n = if (m > 0) m else (Runtime.getRuntime.availableProcessors max 1) min 8
    38       new ThreadPoolExecutor(n, n, 2500L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue[Runnable])
    38       val executor =
       
    39         new ThreadPoolExecutor(n, n, 2500L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue[Runnable])
       
    40       val old_thread_factory = executor.getThreadFactory
       
    41       executor.setThreadFactory(
       
    42         new ThreadFactory {
       
    43           def newThread(r: Runnable) =
       
    44           {
       
    45             val thread = old_thread_factory.newThread(r)
       
    46             thread.setDaemon(true)
       
    47             thread
       
    48           }
       
    49         })
       
    50       executor
    39     }
    51     }
    40 
    52 
    41   lazy val execution_context: ExecutionContextExecutor =
    53   lazy val execution_context: ExecutionContextExecutor =
    42     ExecutionContext.fromExecutorService(pool)
    54     ExecutionContext.fromExecutorService(pool)
    43 
    55