diff options
author | Paul Phillips <paulp@improving.org> | 2010-02-23 00:27:39 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2010-02-23 00:27:39 +0000 |
commit | df94b3c5b831e78a056f7b0b5334b1fb8d3c3bd5 (patch) | |
tree | 6be1d68b93045d6a568ac165126d4ed8e11e3fd7 /src/actors | |
parent | 8d74992310fe60a1da32606949c96531691754e9 (diff) | |
download | scala-df94b3c5b831e78a056f7b0b5334b1fb8d3c3bd5.tar.gz scala-df94b3c5b831e78a056f7b0b5334b1fb8d3c3bd5.tar.bz2 scala-df94b3c5b831e78a056f7b0b5334b1fb8d3c3bd5.zip |
Some much needed housecleaning regarding system...
Some much needed housecleaning regarding system properties. If you can
possibly resist the temptation, it'd be great if people could try to
go through the properties classes to get and set them, and also to set
property values somewhere fixed rather than using strings directly.
Review by community.
Diffstat (limited to 'src/actors')
-rw-r--r-- | src/actors/scala/actors/scheduler/ThreadPoolConfig.scala | 45 |
1 files changed, 15 insertions, 30 deletions
diff --git a/src/actors/scala/actors/scheduler/ThreadPoolConfig.scala b/src/actors/scala/actors/scheduler/ThreadPoolConfig.scala index c34cc83df6..c96dd6d8d3 100644 --- a/src/actors/scala/actors/scheduler/ThreadPoolConfig.scala +++ b/src/actors/scala/actors/scheduler/ThreadPoolConfig.scala @@ -11,6 +11,8 @@ package scala.actors package scheduler +import util.Properties.{ javaVersion, javaVmVendor, isJavaAtLeast, propIsSetTo, propOrNone } + /** * @author Erik Engbrecht * @author Philipp Haller @@ -19,15 +21,9 @@ object ThreadPoolConfig { private val rt = Runtime.getRuntime() private val minNumThreads = 4 - private def getIntegerProp(propName: String): Option[Int] = { - try { - val prop = System.getProperty(propName) - Some(Integer.parseInt(prop)) - } catch { - case se: SecurityException => None - case nfe: NumberFormatException => None - } - } + private def getIntegerProp(propName: String): Option[Int] = + try propOrNone(propName) map (_.toInt) + catch { case _: SecurityException | _: NumberFormatException => None } val corePoolSize = getIntegerProp("actors.corePoolSize") match { case Some(i) if i > 0 => i @@ -38,30 +34,19 @@ object ThreadPoolConfig { } val maxPoolSize = { - val preMaxSize = getIntegerProp("actors.maxPoolSize") match { - case Some(i) => i - case _ => 256 - } + val preMaxSize = getIntegerProp("actors.maxPoolSize") getOrElse 256 if (preMaxSize >= corePoolSize) preMaxSize else corePoolSize } private[actors] def useForkJoin: Boolean = - try { - val fjProp = System.getProperty("actors.enableForkJoin") - if (fjProp != null) - fjProp.equals("true") - else { - val javaVersion = System.getProperty("java.version") - val jvmVendor = System.getProperty("java.vm.vendor") - Debug.info(this+": java.version = "+javaVersion) - Debug.info(this+": java.vm.vendor = "+jvmVendor) - (javaVersion.indexOf("1.6") != -1 || - javaVersion.indexOf("1.7") != -1) && - // on IBM J9 1.6 do not use ForkJoinPool - (jvmVendor.indexOf("Sun") != -1) - } - } catch { - case se: SecurityException => false - } + try propIsSetTo("actors.enableForkJoin", "true") || { + Debug.info(this+": java.version = "+javaVersion) + Debug.info(this+": java.vm.vendor = "+javaVmVendor) + // on IBM J9 1.6 do not use ForkJoinPool + isJavaAtLeast(1.6) && (javaVmVendor contains "Sun") + } + catch { + case _: SecurityException => false + } } |