- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有一段代码需要在 Swing 应用程序以及 Web 应用程序中运行。但它在每个环境中所做的事情应该略有不同。因此我们检查SwingUtilities.isEventDispatchThread()
工作正常一段时间后突然停止工作。它只是卡在该调用上并且永远不会返回。知道为什么会这样吗?
我们在 Linux 机器上使用 java 6,tomcat 7。
更新:
我们删除了对 isEventDispatchThread() 的调用,因此我眼前的问题得到了解决,但我仍然对为什么会发生这种情况的答案感兴趣。
我们进行了更多调试,获得了线程转储并找到了一个线程的以下内容。它表明有许多线程正在等待它。这就解释了悬挂的原因。
java.awt.Toolkit.getDefaultToolkit
似乎导致了锁定,因为它是同步的。所以 Yura 暗示的方向是正确的。
所以问题仍然存在:为什么它没有完成或扭转问题为什么sun.awt.X11GraphicsEnvironment.initDisplay(X11GraphicsEnvironment.java:-1)
挂起?
机器上正在运行 X11 ....
"http-bio-8081-exec-10@10344" daemon prio=5 tid=0x1ae nid=NA runnable
java.lang.Thread.State: RUNNABLE
blocks http-bio-8081-exec-13@10809
blocks http-bio-8081-exec-12@10786
blocks http-bio-8081-exec-11@10343
blocks http-bio-8081-exec-9@10345
blocks http-bio-8081-exec-7@10346
blocks http-bio-8081-exec-6@10347
blocks http-bio-8081-exec-4@10349
blocks http-bio-8081-exec-3@10352
blocks http-bio-8081-exec-2@10353
blocks http-bio-8081-exec-1@10354
at sun.awt.X11GraphicsEnvironment.initDisplay(X11GraphicsEnvironment.java:-1)
at sun.awt.X11GraphicsEnvironment.access$100(X11GraphicsEnvironment.java:52)
at sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:155)
at java.security.AccessController.doPrivileged(AccessController.java:-1)
at sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:131)
at java.lang.Class.forName0(Class.java:-1)
at java.lang.Class.forName(Class.java:169)
at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:68)
- locked <0x2507> (a java.lang.Class)
at sun.awt.X11.XToolkit.<clinit>(XToolkit.java:89)
at java.lang.Class.forName0(Class.java:-1)
at java.lang.Class.forName(Class.java:169)
at java.awt.Toolkit$2.run(Toolkit.java:834)
at java.security.AccessController.doPrivileged(AccessController.java:-1)
at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:826)
- locked <0xf9d> (a java.lang.Class)
at java.awt.Toolkit.getEventQueue(Toolkit.java:1689)
at java.awt.EventQueue.isDispatchThread(EventQueue.java:857)
at javax.swing.SwingUtilities.isEventDispatchThread(SwingUtilities.java:1339)
at xxxxxxxxxA.setCurrentUser(xxxxxxxxxA.java:196)
at xxxxxxxxxB.setCurrentUser(xxxxxxxxxB.java:41)
at xxxxxxxxxC.UserThreadLocalHandler.afterCompletion(xxxxxxxxxC.java:96)
at org.springframework.web.servlet.DispatcherServlet.triggerAfterCompletion(DispatcherServlet.java:1108)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:830)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:669)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:574)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.web.filter.ShallowEtagHeaderFilter.doFilterInternal(ShallowEtagHeaderFilter.java:58)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at com.opensymphony.sitemesh.webapp.SiteMeshFilter.obtainContent(SiteMeshFilter.java:129)
at com.opensymphony.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:77)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:162)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
- locked <0x2a42> (a org.apache.tomcat.util.net.SocketWrapper)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
最佳答案
在底层,SwingUtilities.isEventDispatchThread()
调用 Toolkit.getEventQueue()
方法,该方法具有以下来源:
/* Accessor method for use by AWT package routines. */
static EventQueue getEventQueue() {
return getDefaultToolkit().getSystemEventQueueImpl();
}
Toolkit.getDefaultToolkit
被声明为 synchronized
方法 - 也许就是这种情况。另外,请引用该方法的JavaDoc: http://docs.oracle.com/javase/6/docs/api/java/awt/Toolkit.html#getDefaultToolkit%28%29
希望这有帮助
关于java - 为什么 Web 应用程序卡在 SwingUtilities.isEventDispatchThread() 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10799490/
我是一名优秀的程序员,十分优秀!