簡體   English   中英

Java方法停止被調用

[英]Java method stops being called

我有一台運行大型應用程序的Tomcat服務器。 它具有兩個類似於此示例的類:

public abstract class ClassA {
  private static final Logger LOGGER = Logger.getLogger(ClassA.class);
  // ...
  public File methodA(ICancellable cancel) {
    URL request = new URL("an URL");
    LOGGER.debug("Calling ClassB.methodB(type)");
    File f = classB.methodB(request, "type", cancel);
    LOGGER.debug("The call to ClassB.methodB(type)"
                 + " returned the File==" + f);
    // ...
  }
}

public class ClassB {
  private static final Logger LOGGER = Logger.getLogger(ClassB.class);
  // ...
  public static synchronized File methodB(URL url, String type, 
                                          ICancellable cancel) 
  {
    final String thisMethodsName = "ClassB.methodB(url: " + url 
                           + ", type:" + type + ", cancel: " + cancel + ")";
    LOGGER.debug("Entering method: " + thisMethodsName);
    // ...
    return f;
  }
}

該應用程序正常運行,並且ClassA.methodA()最初成功調用了ClassB.methodB() ,正如我在日志文件中看到的那樣:

[...]
14/02/2013 12:34:56 DEBUG ClassA:123 - Calling ClassB.methodB(type)
14/02/2013 12:34:56 DEBUG ClassB:456 - Entering method: ClassB.methodB(url: anURL, type: type, cancel: @1234);
[...]
14/02/2013 12:34:56 DEBUG ClassA:125 - The call to ClassB.methodB(type) returned the File=="aFile".
[...]

我的問題是服務器工作一段時間后,它停止調用ClassB.methodB() 應用程序被掛起,並將其簡單地寫入日志:

[...]
14/02/2013 12:34:56 DEBUG ClassA:123 - Calling ClassB.methodB(type)

那是日志文件的最后一行。 實際上並未調用ClassB.methodB()

我懷疑這可能是由於打開的資源沒有關閉而引起的,但是我試圖找到執行此操作的所有代碼,並且在修復之后,仍然會發生。

是什么原因造成的? 如何繼續尋找原因?


JVM版本:1.6.0_13 Tomcat版本:6.0.18

是否可能存在涉及某些未粘貼代碼的線程死鎖錯誤? 您的ClassB.methodB方法已synchronized 您可能還有其他一些線程正在持有並且沒有釋放ClassB.class上的synchronized鎖,從而防止正在執行日志記錄的線程獲得該鎖並進入方法。

  1. 啟用調試模式並在代碼中分配斷點。 使用IDE(最好是eclipse)逐步進行。
  2. Eclipse具有諸如findbugs或PMD之類的插件,可以掃描代碼並找出可能的錯誤。
  3. 手動遍歷所有條件,方法調用,循環以查看缺陷。

如果您已經編寫了完整的應用程序,那么您會知道在哪里看。 如果不是,最好檢查一下所有內容

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM