简体   繁体   English

为Java中的计算创建调试网页的最佳方法是什么?

[英]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.

相关问题 什么是创建设置页面的最佳方法 - What is the best way to create an settings page 在 Java 中创建 XML 文件的最佳方法是什么? - What is the best way to create XML files in Java? 在java中创建线程池的最佳方法是什么 - What is the best way to create thread pool in java 在java中创建无限循环的最佳方法是什么? - What is the best way to create an infinite loop in java? 在Java中创建Statement和ResultSet的最佳方法是什么 - What is the best way to create Statement and ResultSet in java 为 java 中的方法创建超时的最佳方法是什么? - what is the best way to create a timeout to a method in java? 创建类似于WCF的JSON / XML REST Web服务的最佳Java方法是什么? - What is the best Java-way to create JSON/XML REST Web services that is similar to WCF? 用Java Web Start程序创建客户机/服务器应用程序的最佳方法是什么? - What is the best way to create a client-server application with a Java Web Start program? Java中检测SeleniumRC网页上元素的最佳方法 - best way to detect an element on a web page for seleniumRC in java 为Web服务编写Java客户端的最佳方法是什么? - What is the best way to write a java client for a web service?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM