java.util.concurrent.ExecutionException: java.lang.NullPointerException 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19229947/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.util.concurrent.ExecutionException: java.lang.NullPointerException Error
提问by Srii
The following code snippet doesnt throw any error when executed in a standalone mode. When I deploy this into a web server [implementing a server's interface and added as JAR into classpath], I get
以下代码片段在独立模式下执行时不会引发任何错误。当我将其部署到 Web 服务器 [实现服务器的接口并作为 JAR 添加到类路径中] 时,我得到
java.util.concurrent.ExecutionException: java.lang.NullPointerException
at java.util.concurrent.FutureTask$Sync.innerGet(Unknown Source)
at java.util.concurrent.FutureTask.get(Unknown Source)
at com.nbis.process.JSON_2_File_Split_V004.fn_1_parserEntity(JSON_2_File_Split_V004.java:256)
at com.nbis.process.JSON_2_File_Split_V004.fn_0_primaryCaller(JSON_2_File_Split_V004.java:177)
at com.nbis.process.JSON_2_File_Split_V004.execute(JSON_2_File_Split_V004.java:151)
Code Snippet:
代码片段:
this.callable = new JSON_3_File_Process_V005(this.originalFileName, this.inProgressDirLoc, this.processedDirLoc, "[" + jSONRecord.toString() + "]", this.dataMDHolder, this.dataAccIDValueMap, this.dataCountryNameValueMap);
String[] fullContent = null;
try {
fullContent = executor.submit(this.callable).get();
} catch (ExecutionException e) {
StringWriter errors = new StringWriter();
e.printStackTrace(new PrintWriter(errors));
log.info("Srii: " + errors.toString());
executor.shutdown();
return 7;
}
Adding the get's return value to an ExecutorCompletionService would be an option, but would that not kill the concept of asynchronous processing? In other words, I collect in StringBuilder the output string from callable get and store to a disk when the get count reaches a specific number. Once data is emitted to disk, I refresh the StringBuilder. This way I push data to a disk at regular intervals without having to keep them in memory.
将 get 的返回值添加到 ExecutorCompletionService 将是一种选择,但这不会扼杀异步处理的概念吗?换句话说,当获取计数达到特定数字时,我在 StringBuilder 中收集来自可调用获取的输出字符串并存储到磁盘。将数据发送到磁盘后,我会刷新 StringBuilder。这样我就可以定期将数据推送到磁盘,而不必将它们保存在内存中。
Any suggestions as to what wrong am I doing here? Appreciate any inputs. Thank you.
关于我在这里做错了什么的任何建议?感谢任何输入。谢谢你。
采纳答案by Srii
This is fixed. If it could useful:
这是固定的。如果它有用:
The problem was with the way the variables were declared. I had to declare a class-level variable as static so the any changes applied to this one started reflecting everywhere else. Strangely enough, I dint see the problem when it was executed stand-alone.
问题在于变量的声明方式。我必须将一个类级变量声明为静态变量,因此应用于此变量的任何更改都开始反映其他地方。奇怪的是,当它独立执行时,我没有看到问题。
EDIT on 13112019: Moving my comment to the answer section, on request:
As its quite long time back, I dont recollect exactly the variable details. But I believe it is one of the following: this.originalFileName, this.inProgressDirLoc, this.processedDirLoc , this.dataMDHolder, this.dataAccIDValueMap, this.dataCountryNameValueMap I had to set them as static as values assigned [or modified] by any of the member was not reflecting during references of the variable within the class.
由于时间很长,我不记得确切的可变细节。但我相信它是以下之一:this.originalFileName、this.inProgressDirLoc、this.processedDirLoc、this.dataMDHolder、this.dataAccIDValueMap、this.dataCountryNameValueMap该成员在类中引用变量期间没有反映。