[英]What is the best way to create a debugging web page for a computation in Java?
I'm developing a website that uses some complex computations (NLP-related). 我正在开发一个使用一些复杂计算(与NLP相关)的网站。 My customer wants to have "debugging" webpages for some of these computations where he can run them with arbitrary input and see all the intermediate results that occur during computation. 我的客户希望为其中的某些计算提供“调试”网页,在这里他可以使用任意输入运行它们,并查看计算过程中发生的所有中间结果。
Before this request all of the computations were encapsulated in beans and intermediate results were logged into general log. 在此请求之前,所有计算都封装在bean中,中间结果记录到常规日志中。
What is the best way to capture all these results on Java level to render them as webpage? 在Java级别捕获所有这些结果以将其呈现为网页的最佳方法是什么?
I'd recommend embedding a servlet container (Apache Tomcat or Jetty, I like Tomcat more) in your application and creating a set of JSP/JSF servlets for the web interface. 我建议在您的应用程序中嵌入一个servlet容器(Apache Tomcat或Jetty,我更喜欢Tomcat),并为Web界面创建一组JSP / JSF servlet。 This solution will let you use all java enterprise technologies (like JAAS) with your web interface and avoid reinventing the wheel. 该解决方案将使您可以在Web界面中使用所有Java企业技术(例如JAAS),并避免重新发明轮子。
I would estimate the effort of creating such solution with tomcat to 1 day of intensive copy/paste. 我估计要用tomcat创建这样的解决方案到1天密集复制/粘贴的工作量。 After the skeleton starts breathing, web pages themselves can be created in Eclipse visual tool with several mouse drags/clicks. 在骨骼开始呼吸之后,可以使用几次鼠标拖动/单击操作,在Eclipse可视化工具中创建网页本身。
The relevant links are how to embed tomcat 6 embedding Jetty Eclipse JSF Tools 相关链接是如何嵌入tomcat 6 嵌入Jetty Eclipse JSF Tools
Finally, I came up the following solution: use an optional ThreadLocal<Map>
in a computation to store intermediate values. 最后,我提出以下解决方案:在计算中使用可选的ThreadLocal<Map>
来存储中间值。 In the end it looks approximately like this: 最后,它看起来像这样:
public class ComplexComputation {
public static final ThreadLocal<Map<String, Object>> DATA
= new ThreadLocal<Map<String, Object>>();
public Result compute(Inputs inputs) {
// ... do something ...
if (DATA.get() != null) { DATA.get().put("intermediate", intermediate); }
// ... do something ...
return result;
}
}
public void computationDebuggingCaller() {
ComplexComputation.DATA.set(new HashMap<String, Object>());
new ComplexComputation().compute(...);
Object intermediate = ComplexComputation.DATA.get().get("intermediate");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.