我有一个有趣的问题——如果我的应用程序运行了很长时间(> 20 小时),那么有时我会收到 NoClassDefFound 错误——似乎 JVM 决定无论如何都不会使用该类并 GCd 它。
更具体地说,这是一个示例:
object ErrorHandler extends PartialFunction[Throwable,Unit] {
def isDefinedAt(t: Throwable) = true
def apply(e: Throwable) =e match {
// ... handle errors
}
}
// somewhere else in the code...
try {
// ... long running code, can take more than 20 hours to complete
} catch (ErrorHandler)
我得到以下异常:
Exception in thread "main" java.lang.NoClassDefFoundError: org/rogach/avalanche/ErrorHandler$
如果该 try/catch 块运行的时间更短,那么一切都会按预期进行。
如果有人感兴趣,这里是有问题的代码库:Avalanche
我需要注意的是,我只在Cent OS 5
使用 JRE 6u26 和 Scala 2.9.1 / 2.9.2 的机器上看到了这个和类似的问题。
这个问题的原因可能是什么?