java-native-access/jna · error · RuntimeException
Unable to pause the service
Error message
Unable to pause the service
What it means
pauseService() sends SERVICE_CONTROL_PAUSE, waits for the service to leave a pending state, and re-queries the status. If the state is not SERVICE_PAUSED, the library throws this RuntimeException because the pause did not take effect.
Solutions
- Verify the service genuinely supports pause (SERVICE_ACCEPT_PAUSE_CONTINUE) and implements it correctly.
- Check the Windows Event Log for service-side failures during pause.
- Catch the exception and re-query status to confirm actual state before retrying or taking corrective action (e.g. stop/start).
- Serialize control operations so no other thread sends controls mid-pause.
Example fix
// before
service.pauseService();
// after
try {
service.pauseService();
} catch (RuntimeException e) {
Winsvc.SERVICE_STATUS st = service.queryStatus();
// decide based on actual state (retry or restart)
} 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"); Try / catch
try {
service.pauseService();
} catch (RuntimeException e) {
Winsvc.SERVICE_STATUS st = service.queryStatus();
if (st.dwCurrentState != Winsvc.SERVICE_PAUSED) { /* retry or restart */ }
} Prevention
- Only pause services known to implement pause correctly.
- Avoid concurrent control requests from multiple threads.
- Re-query status after any failed pause instead of blind retries.
When it happens
Trigger: Calling pauseService() on a service that accepts the PAUSE control but does not end in the PAUSED state — e.g. the service resumes running instead, or stops during the pause attempt.
Common situations: Services with broken or unimplemented pause handlers; control races with a concurrent start/stop; services that only nominally advertise pause support; timeouts in the service's pause path that drop it back to RUNNING.
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
- Unable to continue the service
- Service stop exceeded timeout time of
- Timeout waiting for service to change to a non-pending…
- Could not set proxy blanket.
- DACL is invalid
AI-assisted analysis of java-native-access/jna@d036ad9781 (2026-09-12).
Data as JSON: /api/errors/b9f24d86ab9e0358.
Report an issue: GitHub.
Appendix: source
Thrown at contrib/platform/src/com/sun/jna/platform/win32/W32Service.java:294
}
}
/**
* 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) {
throw new RuntimeException("Unable to pause the service");
}
}
/**
* do not wait longer than the wait hint. A good interval is one-tenth the
* wait hint, but no less than 1 second and no more than 10 seconds.
*/
int sanitizeWaitTime(int dwWaitHint) {
int dwWaitTime = dwWaitHint / 10;
if (dwWaitTime < 1000) {
dwWaitTime = 1000;
} else if (dwWaitTime > 10000) {
dwWaitTime = 10000;
}
return dwWaitTime;
}
View on GitHub (pinned to d036ad9781)