java-native-access/jna · error · RuntimeException

Unable to continue the service

Error message

Unable to continue the service

What it means

continueService() sends SERVICE_CONTROL_CONTINUE, waits for the service to leave a pending state, and then re-queries the status. If the resulting state is not SERVICE_RUNNING, the library throws this RuntimeException because the resume attempt silently failed at the SCM level.

Solutions

  1. Verify the service actually supports pause/continue (check AcceptedControls / sc qfailure flags) before calling continueService.
  2. Inspect the Windows Event Log for service-side errors explaining why resume failed.
  3. Catch the RuntimeException, re-query the status, and decide whether to stop/start the service instead of resuming.
  4. Ensure only one control thread issues pause/continue commands at a time.

Example fix

// before
service.continueService();
// after
try {
    service.continueService();
} catch (RuntimeException e) {
    Winsvc.SERVICE_STATUS st = service.queryStatus();
    if (st.dwCurrentState != Winsvc.SERVICE_RUNNING) {
        service.stopService(30_000);
        service.startService();
    }
}
Defensive patterns

Strategy: try-catch

Validate before calling

Winsvc.SERVICE_STATUS st = service.queryStatus();
if ((st.dwControlsAccepted & Winsvc.SERVICE_ACCEPT_PAUSE_CONTINUE) == 0)
    throw new IllegalStateException("service does not support pause/continue");

Try / catch

try {
    service.continueService();
} catch (RuntimeException e) {
    Winsvc.SERVICE_STATUS st = service.queryStatus();
    if (st.dwCurrentState != Winsvc.SERVICE_RUNNING) { /* stop/start recovery */ }
}

Prevention

When it happens

Trigger: Calling continueService() on a Windows service that accepts the CONTINUE control but ends in a state other than RUNNING (e.g. it returns to PAUSED or STOPPED after resuming), or on a service whose resume path fails internally.

Common situations: Services that do not truly support pause/continue (report SERVICE_ACCEPT_PAUSE_CONTINUE but fail on resume); a service crashes or stops during resume; racing with another control request that changed the final state.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of java-native-access/jna@d036ad9781 (2026-09-12). Data as JSON: /api/errors/c6cc8319366f7f53. Report an issue: GitHub.

Appendix: source

Thrown at contrib/platform/src/com/sun/jna/platform/win32/W32Service.java:275

        }
    }

    /**
     * Continue service.
     */
    public void continueService() {
        waitForNonPendingState();
        // If the service is already stopped - return
        if (queryStatus().dwCurrentState == Winsvc.SERVICE_RUNNING) {
            return;
        }
        if (!Advapi32.INSTANCE.ControlService(_handle, Winsvc.SERVICE_CONTROL_CONTINUE,
                new Winsvc.SERVICE_STATUS())) {
            throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
        }
        waitForNonPendingState();
        if (queryStatus().dwCurrentState != Winsvc.SERVICE_RUNNING) {
            throw new RuntimeException("Unable to continue the service");
        }
    }

    /**
     * Pause service.
     */
    public void pauseService() {
        waitForNonPendingState();
        // If the service is already paused - return
        if (queryStatus().dwCurrentState == Winsvc.SERVICE_PAUSED) {
            return;
        }
        if (!Advapi32.INSTANCE.ControlService(_handle, Winsvc.SERVICE_CONTROL_PAUSE,
                new Winsvc.SERVICE_STATUS())) {
            throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
        }
        waitForNonPendingState();
        if (queryStatus().dwCurrentState != Winsvc.SERVICE_PAUSED) {

View on GitHub (pinned to d036ad9781)