we have a java client/server application, of which the GUI regularly (every half hour) becomes unresponsive for 2 to 10 seconds in average. clicks on different buttons do only take effect after a few seconds of hang time.
I first thought there was a GC issue, but investigation proved nothing's wrong on this side.
I'm more convinced it's a threading issue, with the graphical thread blocking at some moments.
how can I check the status of the graphic thread to witness its "unresponsiveness" in my log ? I imagine I could check its state every second or so from a different thread, b开发者_StackOverflow中文版ut how to do so ? which variable to poll ?
any other idea on how to tackle this ?
thanks
You can issue a kill -QUIT
to the Java process (and something equivalent on Windows), which will cause all threads to dump their stacktraces to STDOUT, so you can see what is going on. This also shows which threads are holding locks (synchronized blocks) and which are waiting.
If you cannot reproduce the problem in test, and cannot shut down production, then there is not a simple answer to your question.
It seems like you might have bigger problems that have to be diagnosed using some kind of profiling tool. We use JProbe & JProfiler and have had a lot of luck with it.
Worst case, you can use JMX to essentially write your own code that does something along the lines of this link. It has been very useful to me in the past.
http://www.javamex.com/tutorials/profiling/profiling_java5_threads_methodology.shtml
To get an idea of how long the ui thread is blocked, you can do something like,
ScheduledThreadPoolExecutor executor = ....
executor.scheduleAtFixedRate(new Runnable(){
public void run() {testEventThread();}}, 5, 5, TimeUnit.SECONDS);
void testEventThread() {
final long now = System.currentTimeMillis();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
System.out.println("event thread took:" + (System.currentTimeMillis()- now) + " to respond");
}
});
}
精彩评论