summaryrefslogtreecommitdiff
path: root/src/dotnet-library/scala/Application.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2009-05-02 13:21:17 +0000
committerPaul Phillips <paulp@improving.org>2009-05-02 13:21:17 +0000
commit2bb5db8e23f54ecea3bc82c48d408ec61c3cd25b (patch)
tree99ccc3aa4c0edacfb907df35e61b0b47f3c331cf /src/dotnet-library/scala/Application.scala
parent4603e36f932a18eb17a41aecc6b9e74c7655ff0f (diff)
downloadscala-2bb5db8e23f54ecea3bc82c48d408ec61c3cd25b.tar.gz
scala-2bb5db8e23f54ecea3bc82c48d408ec61c3cd25b.tar.bz2
scala-2bb5db8e23f54ecea3bc82c48d408ec61c3cd25b.zip
Synced src/dotnet-library with rev 17621 of src...
Synced src/dotnet-library with rev 17621 of src/library
Diffstat (limited to 'src/dotnet-library/scala/Application.scala')
-rw-r--r--src/dotnet-library/scala/Application.scala38
1 files changed, 35 insertions, 3 deletions
diff --git a/src/dotnet-library/scala/Application.scala b/src/dotnet-library/scala/Application.scala
index 4867b2eb99..3d94db28ec 100644
--- a/src/dotnet-library/scala/Application.scala
+++ b/src/dotnet-library/scala/Application.scala
@@ -15,8 +15,9 @@ package scala
//import scala.compat.Platform.currentTime
/** <p>
- * The <code>Application</code> class can be used to quickly turn objects
- * into executable programs. Here is an example:
+ * The <code>Application</code> trait can be used to quickly turn objects
+ * into executable programs, but is <em>not recommended</em>.
+ * Here is an example:
* </p><pre>
* object Main with Application {
* Console.println("Hello World!");
@@ -36,6 +37,37 @@ package scala
* </p><pre>
* java -Dscala.time Main
* </pre>
+ * <p>
+ * In practice the <code>Application</code> trait has a number of serious
+ * pitfalls:
+ * </p>
+ * <ul>
+ * <li> Threaded code that references the object will block until static
+ * initialization is complete. However, because the entire execution of an
+ * <code>object</code> extending <code>Application</code> takes place during
+ * static initialization, concurrent code will <em>always</em> deadlock if
+ * it must synchronize with the enclosing object.</li>
+ * <li>As described above, there is no way to obtain the
+ * command-line arguments because all code in body of an <code>object</code>
+ * extending <code>Application</code> is run as part of the static initialization
+ * which occurs before <code>Application</code>'s <code>main</code> method
+ * even begins execution.</li>
+ * <li>Static initializers are run only once during program execution, and
+ * JVM authors usually assume their execution to be relatively short.
+ * Therefore, certain JVM configurations may become confused, or simply fail to
+ * optimize or JIT the code in the body of an <code>object</code> extending
+ * <code>Application</code>. This can lead to a significant
+ * performance degradation.</li>
+ * </ul>
+ *
+ * Instead, it is recommended to define a <code>main</code> method explicitly:
+ * <pre>
+ * <b>object</b> Main {
+ * <b>def</b> main(args: Array[String]) {
+ * //..
+ * }
+ * }
+ * </pre>
*
* @author Matthias Zenger
* @version 1.0, 10/09/2003
@@ -51,7 +83,7 @@ trait Application {
*
* @param args the arguments passed to the main method
*/
- def main(args: Array[String]) = {
+ def main(args: Array[String]) {
// if (getProperty("scala.time") ne null) {
// val total = currentTime - executionStart
// Console.println("[total " + total + "ms]")