开发者

What can cause a hanging in this "harmless" sequence of Java commands?

One of the constructors has the following sequence of the commands:

log.info("A new session of the game started.");
clientsListener = new ClientsListener(earPort, userName, players, this);

In the log file I have the statement produced by the first line of the code. The constructor of the ClientsListener is written in the following way:

public ClientsListener(int earPort, String userName, String[] players, Game game) {
   this.earPort = earPort;
   this.userName = userName;
   this.players = players;
   this.game = game;
   ServiceBrowser browser;
   for (String playerName: players) {
      String serviceType = "_" + playerName + "._tcp.";
      browser = BrowsersGenerator.getBrowser(serviceType,game);
      browser.post(userName + ":infoRequest=infoRequest");
   }
}

The BrowsersGenerator.getBrowser has the following simple sequence of commands:

public static ServiceBrowser getBrowser(String serviceType, Game game) {
   if (!name2browser.containsKey(serviceType)) {
      name2browser.put(serviceType, new ServiceBrowser(serviceType, game));
   }
   return name2browser.get(serviceType);
}

In the above method I instantiate the ServiceBrowser. The constructor of this class is:

public ServiceBrowser(String serviceType, Game game) {
   this.serviceType = serviceType;
   this.game = game;
   status = "notActivated";
}

Then, in the constructor of the ClientsListener (the second block of the code) I call browser.post. The first line of this method contains the following:

game.log.fine("We entered the post method");

A开发者_Python百科nd this statement is absent in the log file. So, the software hangs somewhere between the two attempts to write to the log file. I cannot figure out where is a gangrenous part of the code. Everything looks save to me. The main problem is that I cannot reproduce the problem. I happens very rare and I have only one log file to analyze. Could anybody, please, help me with that?


If browser.post() is doing what it says, everything can happen. But most likely, your program is hanging while waiting for a response not given from some firewall.


You seem to have subclasses of ServiceBrowser. Are you sure they all have a log command at the start of their post method too? Also you could try to see if you hang when a specific type of ServiceBrowser is called.

When your process is hanging you can use some tools like jconsole or jstat on the remote java process to view the current stack trace and figure out where it is hanging.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜