Vertx:关闭PDF文件后保持服务器活着

时间:2016-04-06 19:26:03

标签: java jasper-reports vert.x

我使用Vertx和Jasper Reports,我可以成功创建我的报告但是当我关闭PDF文件服务器时停止运行。我想让我的服务器继续运行。

这是我的代码:

 public void start(Future<Void> startFuture){
    String fileJSON = "{name : 'Stackoverflow', start: '15-06-2014', end: '02-09-2018'}";
    String file =  "/Test1";
    Router router = Router.router(vertx);
       router.route(file).handler(routingContext -> {
        HttpServerResponse response = routingContext.response();
        response.setChunked(true);            
        InputStream iostream = new ByteArrayInputStream(fileJSON.getBytes(StandardCharsets.UTF_8));
                try{                                  
                    JsonDataSource ds = new JsonDataSource(iostream);
                    Map parametersMap = new HashMap();  
                    String report = "C:\\PathToreport\\report2.jrxml";
                    JasperReport Jasp = JasperCompileManager.compileReport(report);
                    JasperPrint JASP_PRINT = JasperFillManager.fillReport(Jasp,parametersMap,ds);
                    JasperViewer.viewReport(JASP_PRINT);
                    JasperExportManager.exportReportToPdfFile(JASP_PRINT, "C:\\Users\\path\\report4.pdf");                             
                    }
                catch(Exception e){ System.out.println(e);}
        routingContext.vertx().setTimer(1000, tid ->  routingContext.response().end());
    });
    vertx.createHttpServer()
            .requestHandler(router::accept)
            .listen(8089, "localhost", res -> {

                if (res.succeeded()){

                    startFuture.complete();    
                }
                else
                    startFuture.fail(res.cause());
            });


}

这是堆栈:

vr. 07, 2016 9:25:04 AM io.vertx.core.impl.BlockedThreadChecker AVERTISSEMENT: Thread Thread[vert.x-eventloop-thread-1,5,main] has been blocked for 2407 ms, time limit is 2000 avr. 07, 2016 9:25:05 AM io.vertx.core.impl.BlockedThreadChecker AVERTISSEMENT: Thread Thread[vert.x-eventloop-thread-1,5,main] has been blocked for 3407 ms, time limit is 2000 avr. 07, 2016 9:25:06 AM io.vertx.core.impl.BlockedThreadChecker AVERTISSEMENT: Thread Thread[vert.x-eventloop-thread-1,5,main] has been blocked for 4407 ms, time limit is 2000 BUILD SUCCESSFUL (total time: 27 seconds)

1 个答案:

答案 0 :(得分:0)

解决了,我不得不在viewReport

中添加false参数

JasperViewer.viewReport(JASP_PRINT,false);