gpt4 book ai didi

java - java servlet 调用永远不会到达 servlet

转载 作者:太空宇宙 更新时间:2023-11-04 12:18:14 30 4
gpt4 key购买 nike

我有一个 Java Web 应用程序,已部署在 Wildfly 10 Web 服务器中。该应用程序在大多数时间都工作正常,但出乎意料的是,对 java servlet 的调用从未到达 servlet。

我感到好奇并分析了 VisualVM 中 Wildfly 服务器的线程转储。虽然我不是分析线程转储的专家,但我预计会发生一些线程锁,因为该 servlet 调用的任务线程永远不会执行;永远等待。

现在我不知道这是否是应用程序方面的问题。我怀疑这是我设置为默认的 servlet 容器配置的问题,或者这是一些野蝇错误?...,我希望不是这样。请回复。

这是我的登录 servlet 代码:

 response.setContentType("application/json");
UserInfo user = null;
boolean authenticated = false;
String message = "";
String ipAddress = request.getHeader("X-FORWARDED-FOR");
if (ipAddress == null) {
ipAddress = request.getRemoteAddr();
}

try {
ApplicationHelper.clearSession(request);
String body = request.getReader().lines().reduce("", (accumulator, actual) -> accumulator + actual);
HashMap inputDataMap = new ObjectMapper().readValue(body, HashMap.class);
String userName = (String) inputDataMap.get("username");
String password = (String) inputDataMap.get("password");
user = UserDataProvider.verifyEncryptedAccount(userName, password);

if (user != null) {
UserDataProvider.updateLoginStatus(user.getIdKey(), request.getSession().getId(), ipAddress, true);
request.getSession(true).setAttribute("userInfo", user);
authenticated = true;
message = MPHLTHConstants.Success;
} else {
throw new InsufficientAccessException("Insufficient access");
}

} catch (Exception ex) {
authenticated = false;
if (ex instanceof ApplicationException) {
message = ex.getMessage();
}
ExceptionDataProvider.logException(ex, request, user);
} finally {
try {
Response objResponse = new Response(user, message, authenticated, 1);
Map<String, String[]> jsonFilters = new HashMap<>();
jsonFilters.put("ResponseFilter", new String[0]);
jsonFilters.put("UserInfoFilter", new String[0]);
JSONHelper.writeJSONResponse(objResponse, response, jsonFilters);
} catch (Exception ex) {
ExceptionDataProvider.logException(ex, request, user);
}
}

这些是我看到锁的线程,我在不同的时间看到了其中的几个线程,并且这些线程没有随着时间的推移而改变:

"default task-64" #206 prio=5 os_prio=0 tid=0x000000001c59b800 nid=0x5608 waiting for monitor entry [0x000000001f8bd000]   java.lang.Thread.State: BLOCKED (on object monitor)
at java.io.PrintStream.println(PrintStream.java:805)
- waiting to lock <0x00000000e0058f58> (a java.io.PrintStream)
at org.jboss.stdio.StdioContext$DelegatingPrintStream.println(StdioContext.java:474

还有这个:

> "default task-61" #203 prio=5 os_prio=0 tid=0x000000001c599000 nid=0x4934 runnable [0x000000001f5bd000]
java.lang.Thread.State: RUNNABLE
at java.io.FileOutputStream.writeBytes(Native Method)
at java.io.FileOutputStream.write(FileOutputStream.java:326)
at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)
- locked <0x00000000e0aeb790> (a java.io.BufferedOutputStream)
at java.io.PrintStream.write(PrintStream.java:482)
- locked <0x00000000e0aeb770> (a java.io.PrintStream)
at org.jboss.logmanager.handlers.UncloseableOutputStream.write(UncloseableOutputStream.java:44)
at org.jboss.logmanager.handlers.UninterruptibleOutputStream.write(UninterruptibleOutputStream.java:84)
at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:221)
at sun.nio.cs.StreamEncoder.implFlushBuffer(StreamEncoder.java:291)
at sun.nio.cs.StreamEncoder.implFlush(StreamEncoder.java:295)
at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:141)
- locked <0x00000000e0aeb738> (a java.io.OutputStreamWriter)
at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:229)
at java.io.BufferedWriter.flush(BufferedWriter.java:254)
- locked <0x00000000e0aeb738> (a java.io.OutputStreamWriter)
at org.jboss.logmanager.handlers.WriterHandler.safeFlush(WriterHandler.java:170)
at org.jboss.logmanager.handlers.WriterHandler.flush(WriterHandler.java:139)
- locked <0x00000000e0aeb700> (a java.lang.Object)
at org.jboss.logmanager.ExtHandler.doPublish(ExtHandler.java:104)
at org.jboss.logmanager.handlers.WriterHandler.doPublish(WriterHandler.java:67)
- locked <0x00000000e0aeb700> (a java.lang.Object)
at org.jboss.logmanager.ExtHandler.publish(ExtHandler.java:76)
at org.jboss.logmanager.LoggerNode.publish(LoggerNode.java:314)
at org.jboss.logmanager.LoggerNode.publish(LoggerNode.java:322)
at org.jboss.logmanager.Logger.logRaw(Logger.java:850)
at org.jboss.logmanager.Logger.log(Logger.java:596)
at org.jboss.stdio.AbstractLoggingWriter.write(AbstractLoggingWriter.java:71)
- locked <0x00000000e0058fb8> (a java.lang.StringBuilder)
at org.jboss.stdio.WriterOutputStream.finish(WriterOutputStream.java:143)
at org.jboss.stdio.WriterOutputStream.flush(WriterOutputStream.java:164)
- locked <0x00000000e0059128> (a sun.nio.cs.SingleByte$Decoder)
at java.io.PrintStream.write(PrintStream.java:482)
- locked <0x00000000e0058f58> (a java.io.PrintStream)
at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:221)
at sun.nio.cs.StreamEncoder.implFlushBuffer(StreamEncoder.java:291)
at sun.nio.cs.StreamEncoder.flushBuffer(StreamEncoder.java:104)
- locked <0x00000000e00579c0> (a java.io.OutputStreamWriter)
at java.io.OutputStreamWriter.flushBuffer(OutputStreamWriter.java:185)
at java.io.PrintStream.newLine(PrintStream.java:546)
- locked <0x00000000e0058f58> (a java.io.PrintStream)
at java.io.PrintStream.println(PrintStream.java:807)
- locked <0x00000000e0058f58> (a java.io.PrintStream)
at org.jboss.stdio.StdioContext$DelegatingPrintStream.println(StdioContext.java:474)

最佳答案

这个问题终于解决了。我们发现线程锁定是由于应用程序中多个位置存在 println() 语句而发生的。 WildFly 10 中的日志记录子系统和 println() 语句对打印输出流创建锁定,并最终陷入死锁。

关于java - java servlet 调用永远不会到达 servlet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39138816/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com