0
votes

I'm a Java programmer and started studying Scala in my free time. Have this little problem driving me mad...

Every time I run a Scala script, at the end of the execution, the jvm doesn't quit, and I always have to kill the process by myself, which is quite annoying

The case is the following: given the little hello world in main.scala file

object Main {
    def main(args: Array[String]): Unit = {
       println("Hello world")
    }
}

run it with

scala main.scala

then with ps -ef I have

501 5739 5727 0 9:46PM ttys000 0:18.08 /usr/bin/java -Xmx256M -Xms32M -Xbootclasspath/a:/MyStuff/ScalaFiles/scala-2.10.1/lib/akka-actors.jar:/MyStuff/ScalaFiles/scala-2.10.1/lib/jline.jar:/MyStuff/ScalaFiles/scala-2.10.1/lib/scala-actors-migration.jar:/MyStuff/ScalaFiles/scala-2.10.1/lib/scala-actors.jar:/MyStuff/ScalaFiles/scala-2.10.1/lib/scala-compiler.jar:/MyStuff/ScalaFiles/scala-2.10.1/lib/scala-library.jar:/MyStuff/ScalaFiles/scala-2.10.1/lib/scala-partest.jar:/MyStuff/ScalaFiles/scala-2.10.1/lib/scala-reflect.jar:/MyStuff/ScalaFiles/scala-2.10.1/lib/scala-swing.jar:/MyStuff/ScalaFiles/scala-2.10.1/lib/scalap.jar:/MyStuff/ScalaFiles/scala-2.10.1/lib/typesafe-config.jar -classpath "" -Dscala.home=/MyStuff/ScalaFiles/scala-2.10.1 -Dscala.usejavacp=true scala.tools.nsc.MainGenericRunner scala.tools.nsc.CompileServer

which of course is the jvm, and have to quit it by myself.

I tried putting

System.exit(0)

or sys.exit(0)

but nothing changed. Do you have the same issue?

Thanks a lot

1
scala.tools.nsc. CompileServer, it is not a program you've runned: it is compiling server which runs in background to speedup compilation speed and avoid startup overhead - om-nom-nom
Thanks, the problem is the compileServer. Can't I set up a time to live for the server? however using scalac the problem doesn't show... - besil
if this is fsc you can either issue fsc -shutdown to completely stop instance or provide -max-idle n option at fsc start (perhaps in sbt definition, but I'm not sure), where n is time in minutes after which fsc goes down, 0 is for immortal fsc. - om-nom-nom
@besil were you able to get around this problem? - Rahul Tanwani

1 Answers

0
votes

You might want to investigate a different approach to run scala script:

  • The most advanced one is using scalas from SBT which allow you to deal with dependencies