Java 异步JAX-RS实现中的NullPointerException
我正在尝试实现异步JAX-RS。下面是我的代码:Java 异步JAX-RS实现中的NullPointerException,java,web-services,asynchronous,nullpointerexception,jax-rs,Java,Web Services,Asynchronous,Nullpointerexception,Jax Rs,我正在尝试实现异步JAX-RS。下面是我的代码: @GET @Path("/isAlive") @Produces(MediaType.TEXT_HTML) public void isAlive(@Suspended AsyncResponse ar) { executor.execute(() -> { System.out.println("Inside"); Connection co
@GET
@Path("/isAlive")
@Produces(MediaType.TEXT_HTML)
public void isAlive(@Suspended AsyncResponse ar) {
executor.execute(() -> {
System.out.println("Inside");
Connection conn = ConnectionUtil.getDBConnection();
PreparedStatement stmt;
int i = 0;
try {
stmt = conn.prepareStatement("insert into TEST_TABLE values(?)");
stmt.setString(1, "TEST INSERT");
i = stmt.executeUpdate();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
ar.resume(i);
});
}
执行上述代码后,我在ar.resume(I)
处收到一个Nulpointerexception
我怎么会在这里?如果我删除
ar.resume(I)
部分,它工作正常。那么我为什么和什么时候应该使用resume()
方法?PublishWSImpl.java中的第51行是哪一行?它是ar.resume(I)。
13:31:35,286 ERROR [stderr] (pool-5-thread-1) Exception in thread "pool-5-thread-1" java.lang.NullPointerException
13:31:35,286 ERROR [stderr] (pool-5-thread-1) at com.test.PublishWSImpl.lambda$0(PublishWSImpl.java:51)
13:31:35,286 ERROR [stderr] (pool-5-thread-1) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
13:31:35,287 ERROR [stderr] (pool-5-thread-1) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)