How to Manage the IronPdfEngine Lifecycle in Java
The IronPdfEngineManager class in the com.ironsoftware.ironpdf package provides static, thread-safe methods to check whether the IronPdfEngine is alive and to start, stop, or restart it. The engine lifecycle is automatic by default: it starts on the first IronPDF call and stops on application shutdown, so most applications never need this API.
It exists for long-running services (web applications, background daemons, and batch processors) where the engine can be interrupted by events outside IronPDF's control: a remote engine host restart, an OS kill signal, or a native process crash. Previously there was no supported way to detect a dead engine or force a reconnect. The class fills that gap with four methods: isEngineActive(), startEngine(), stopEngine(), and restartEngine().
Start a free 30-day trial to test engine lifecycle management in a live environment.
//:path=/static-assets/ironpdf-java/content-code-examples/how-to/ironpdfengine-lifecycle/watchdog.java
import com.ironsoftware.ironpdf.IronPdfEngineManager;
import com.ironsoftware.ironpdf.PdfDocument;
// Recover automatically if the engine was interrupted (host restart, crash, kill).
if (!IronPdfEngineManager.isEngineActive()) {
IronPdfEngineManager.restartEngine();
}
PdfDocument pdf = PdfDocument.renderHtmlAsPdf("<h1>Hello World</h1>");
pdf.saveAs("output.pdf");
//:path=/static-assets/ironpdf-java/content-code-examples/how-to/ironpdfengine-lifecycle/watchdog.java
import com.ironsoftware.ironpdf.IronPdfEngineManager;
import com.ironsoftware.ironpdf.PdfDocument;
// Recover automatically if the engine was interrupted (host restart, crash, kill).
if (!IronPdfEngineManager.isEngineActive()) {
IronPdfEngineManager.restartEngine();
}
PdfDocument pdf = PdfDocument.renderHtmlAsPdf("<h1>Hello World</h1>");
pdf.saveAs("output.pdf");
Quickstart
Minimal Workflow (3 Steps)
- Add the IronPDF dependency to the project via Maven
- Call
isEngineActive()to check whether the engine is connected - Call
restartEngine()to recover if the check returnsfalse
How Does the Engine Lifecycle Work?
The IronPdfEngine is a native subprocess that IronPDF for Java communicates with over gRPC. The lifecycle has two automatic phases:
- Start: The engine starts the first time any IronPDF method is called (for example
PdfDocument.renderHtmlAsPdf()). - Stop: The engine shuts down when the JVM exits. Calling
stopEngine()triggers an early shutdown, and the engine restarts automatically on the next IronPDF call.
Manual control becomes necessary when the engine dies unexpectedly. Any of those interruptions leaves IronPDF holding a stale gRPC connection, and subsequent calls may fail or hang. IronPdfEngineManager provides the mechanism to detect this state and recover from it.
Multiple threads can call these methods concurrently without synchronization. If one thread is already performing a restart, other callers wait for it to finish rather than triggering a second restart.
How to Check Engine Health?
isEngineActive() returns true only if the engine is connected and responds to an internal handshake. It never starts the engine; it reports the current connection state without side effects.
//:path=/static-assets/ironpdf-java/content-code-examples/how-to/ironpdfengine-lifecycle/health-check.java
import com.ironsoftware.ironpdf.IronPdfEngineManager;
boolean healthy = IronPdfEngineManager.isEngineActive();
System.out.println("Engine status: " + (healthy ? "active" : "not responding"));
//:path=/static-assets/ironpdf-java/content-code-examples/how-to/ironpdfengine-lifecycle/health-check.java
import com.ironsoftware.ironpdf.IronPdfEngineManager;
boolean healthy = IronPdfEngineManager.isEngineActive();
System.out.println("Engine status: " + (healthy ? "active" : "not responding"));
Output
With the engine running, the check prints its status to the console.
Engine status: active
The IronSuite play a crucial role in our operations. These are tools that increase efficiencies across the business including creating floor plans and improving inventory management.
How to Restart a Failed Engine?
restartEngine() is the recommended recovery action. It stops the current connection, clears stale internal state, and establishes a fresh gRPC channel. That is more thorough than calling stopEngine() then startEngine(): it resets connection state a normal IronPDF call would not.
The core watchdog is the quickstart above: check isEngineActive(), and call restartEngine() when it returns false. Run that check per request for low-traffic services, or on a schedule to keep the engine warm between requests. Wrap the recovery in a try/catch, because restartEngine() itself throws if the engine host is still unreachable; log the failure and let the next attempt retry rather than looping tightly.
The following Spring Boot example polls every 60 seconds:
//:path=/static-assets/ironpdf-java/content-code-examples/how-to/ironpdfengine-lifecycle/spring-watchdog.java
import com.ironsoftware.ironpdf.IronPdfEngineManager;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
public class EngineWatchdog {
@Scheduled(fixedRate = 60000)
public void checkEngine() {
if (!IronPdfEngineManager.isEngineActive()) {
try {
IronPdfEngineManager.restartEngine();
} catch (Exception e) {
// Engine host still unreachable; log it and let the next tick retry.
System.err.println("IronPdfEngine restart failed: " + e.getMessage());
}
}
}
}
//:path=/static-assets/ironpdf-java/content-code-examples/how-to/ironpdfengine-lifecycle/spring-watchdog.java
import com.ironsoftware.ironpdf.IronPdfEngineManager;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
public class EngineWatchdog {
@Scheduled(fixedRate = 60000)
public void checkEngine() {
if (!IronPdfEngineManager.isEngineActive()) {
try {
IronPdfEngineManager.restartEngine();
} catch (Exception e) {
// Engine host still unreachable; log it and let the next tick retry.
System.err.println("IronPdfEngine restart failed: " + e.getMessage());
}
}
}
}
Output
A manual stop and restart shows the recovery step working, isEngineActive returns false after a stop and true again after restartEngine.
isEngineActive() after stop: false
Restarting IronPdfEngine
isEngineActive() after restart: true
How to Stop and Start the Engine Manually?
stopEngine() shuts down the local subprocess or closes the remote gRPC connection. startEngine() initializes the engine, the same operation that happens implicitly on the first IronPDF call, and is a no-op on an already-healthy engine.
//:path=/static-assets/ironpdf-java/content-code-examples/how-to/ironpdfengine-lifecycle/stop-start.java
import com.ironsoftware.ironpdf.IronPdfEngineManager;
// Release native resources during a long idle period
IronPdfEngineManager.stopEngine();
// Start again before the next batch (or let the next IronPDF call do it)
IronPdfEngineManager.startEngine();
//:path=/static-assets/ironpdf-java/content-code-examples/how-to/ironpdfengine-lifecycle/stop-start.java
import com.ironsoftware.ironpdf.IronPdfEngineManager;
// Release native resources during a long idle period
IronPdfEngineManager.stopEngine();
// Start again before the next batch (or let the next IronPDF call do it)
IronPdfEngineManager.startEngine();
The stop-start pattern suits batch processors that run at scheduled intervals with long idle periods. Stopping the engine during idle time frees native memory and process resources, and it restarts cleanly via startEngine() or automatically on the next IronPDF call. For recovery from an unexpected failure, prefer restartEngine().
What Are the Connection Mode Limitations?
All four methods work in the default subprocess mode and in host-port/target remote modes. The exception is a custom gRPC channel configured via IronPdfEngineConnection.withCustomGrpcConnection(...): there, stopEngine() and restartEngine() throw UnsupportedOperationException.
The reason is ownership. In custom mode the caller owns the gRPC channel, and IronPDF cannot rebuild a channel it did not create, so shutting it down would leave the library in an unrecoverable state. Channel lifecycle is the caller's responsibility.
| Method | Subprocess | Host-Port / Target | Custom gRPC |
|---|---|---|---|
isEngineActive() |
✅ | ✅ | ✅ |
startEngine() |
✅ | ✅ | ✅ |
stopEngine() |
✅ | ✅ | ❌ throws UnsupportedOperationException |
restartEngine() |
✅ | ✅ | ❌ throws UnsupportedOperationException |
The IronPdfEngine connection modes guide documents all supported configurations. With a custom channel, implement health checking and reconnection directly on the channel using standard gRPC health-check patterns.
Next Steps
IronPdfEngineManager gives long-running Java services a supported way to detect and recover an interrupted engine, plus explicit resource control for batch workloads with idle periods.
The IronPdfEngine setup guide covers connection mode configuration for local and remote engines. The IronPDF for Java documentation provides the full getting-started workflow, and the IronPdfEngine Docker guide covers containerized deployments including gRPC health checking at the infrastructure level. The Java changelog tracks engine improvements and version compatibility.
View licensing options starting at $749. The Java API reference documents the complete IronPdfEngineManager class surface.


