IRONSOFTWAREHOME
檢查並重啟 IronPdfEngine

import com.ironsoftware.ironpdf.*;

// Recover automatically if IronPdfEngine was interrupted (host restart, crash, or kill)
if (!IronPdfEngineManager.isEngineActive()) {
    IronPdfEngineManager.restartEngine();
}

// Continue as normal; the engine is now guaranteed to be connected
PdfDocument pdf = PdfDocument.renderHtmlAsPdf("<h1>Hello World</h1>");
pdf.saveAs("output.pdf");
mvn install
檢查並重啟 IronPdfEngine

檢查並重啟 IronPdfEngine

IronPdfEngine 為 IronPDF for Java 執行每個 PDF 操作,並自動管理其生命週期:在第一次調用時啟動,並在應用程式退出時停止。長時間運行的服務偶爾需要介入,例如當遠端主機重啟、操作系統 kill 或本機崩潰中斷引擎時。IronPdfEngineManager 類提供靜態、線程安全的方法來檢查引擎的健康狀況以及啟動、停止或重啟它。

此代碼範例使用了看門狗模式。IronPdfEngineManager.isEngineActive() 報告引擎是否已連接,而 IronPdfEngineManager.restartEngine() 在未連接時強制進行乾淨的重新連接,在下一次渲染之前清除陳舊的連接狀態。restartEngine() 是推薦的恢復操作。大多數應用程式不需要它,因為生命週期是自動的,但對於必須保持可用的服務來說,它是有價值的。

當您通過 IronPdfEngineConnection.withCustomGrpcConnection 提供自己的 gRPC 通道時,有一個限制:stopEngine() 和 restartEngine() 在該模式下不可用,因為調用者擁有通道,而 isEngineActive() 和 startEngine() 在任何地方都可以使用。

在設置 IronPdfEngine 指南中了解更多。

準備好開始了嗎?

版本:2026.6剛剛發布

Key in blue circle

立即免費取得 30 天試用金鑰。

Your trial license will be sent to your email address

無任何限制。100% 解鎖。無需信用卡。

OR
bullet_checked無需信用卡或建立帳號無任何限制。100% 解鎖。無需信用卡。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried Iron Suite
預訂您的免費 即時演示
Booking Badge

全球數百萬工程師的信任

Iron Software的客戶商標
獲取您的無義務諮詢
填寫以下表格或發送電子郵件至sales@ironsoftware.com
您的詳細資訊始終保持機密。
全球數百萬工程師的信任
Iron Software的客戶商標
立即獲取您的30天試用金鑰。
無需信用卡或帳戶建立
PDF的Java Maven程式庫
using Maven 安裝

版本: 2026.6

<dependency>
   <groupId>com.ironsoftware</groupId>
   <artifactId>ironpdf</artifactId>
   <version>2026.6.1</version>
</dependency>
https://central.sonatype.com/artifact/com.ironsoftware/ironpdf/2026.6.1
or
Java PDF JAR
下載 JAR

版本: 2026.6

手動安裝到您的專案中