You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This resulting classloader is unable to load resources from the system classpath, so any code you call from within the console may fail. For example, the Hadoop project uses the context class loader to obtain configuration files from the jars. But it will fail to find config entries (bad):
scala> val c = new Configuration
c: org.apache.hadoop.conf.Configuration = Configuration: core-default.xml, core-site.xml
scala> c.size
res12: Int = 0
One cannot set the Thread.currentThread.setContextClassLoader because every new line is a new thread. Thus perhaps one could fix it by doing a block first setting the context class loader, then calling the code which needs it like such.
Essentially the result is legitimate code which will run in a script/app in scala will not run in a console.
The text was updated successfully, but these errors were encountered:
@retronym said (edited on Jan 20, 2012 10:04:21 PM UTC): scala -Dscala.repl.no-threads=true or scala -Yrepl-sync avoids spawning new threads for each line in Scala 2.9.1
In Scala 2.10.0-M1, this is classloader covers classes created during the REPL session.
~/code/scala scala210 -Yrepl-sync
Welcome to Scala version 2.10.0-M1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_29).
Type in expressions to have them evaluated.
Type :help for more information.
scala> class C
defined class C
scala> Thread.currentThread.getContextClassLoader.loadClass(classOf[C].getName)
res0: Class[_] = class C
Thread.currentThread.getContextClassLoader returns a stub of a classloader:
scala> Thread.currentThread.getContextClassLoader
res15: java.lang.ClassLoader = sun.misc.Launcher$AppClassLoader@53004901
This resulting classloader is unable to load resources from the system classpath, so any code you call from within the console may fail. For example, the Hadoop project uses the context class loader to obtain configuration files from the jars. But it will fail to find config entries (bad):
scala> val c = new Configuration
c: org.apache.hadoop.conf.Configuration = Configuration: core-default.xml, core-site.xml
scala> c.size
res12: Int = 0
One cannot set the Thread.currentThread.setContextClassLoader because every new line is a new thread. Thus perhaps one could fix it by doing a block first setting the context class loader, then calling the code which needs it like such.
Essentially the result is legitimate code which will run in a script/app in scala will not run in a console.
The text was updated successfully, but these errors were encountered: