{"record":{"id":"00d6a5008b089eb4","repo":"apache/pulsar","slug":"not-support-to-set-continueexistingperiodictasksaf","errorCode":null,"errorMessage":"Not support to set continueExistingPeriodicTasksAfterShutdownPolicy, it is always false","messagePattern":"Not support to set continueExistingPeriodicTasksAfterShutdownPolicy, it is always false","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"pulsar-common/src/main/java/org/apache/pulsar/common/util/SingleThreadNonConcurrentFixedRateScheduler.java","lineNumber":199,"sourceCode":"     * Long.MAX_VALUE.\n     */\n    private long overflowFree(long delay) {\n        Delayed head = (Delayed) super.getQueue().peek();\n        if (head != null) {\n            long headDelay = head.getDelay(NANOSECONDS);\n            if (headDelay < 0 && (delay - headDelay < 0)) {\n                delay = Long.MAX_VALUE + headDelay;\n            }\n        }\n        return delay;\n    }\n\n    /**\n     * {@inheritDoc}\n     */\n    @Override\n    public void setContinueExistingPeriodicTasksAfterShutdownPolicy(boolean flag) {\n        throw new IllegalArgumentException(\"Not support to set continueExistingPeriodicTasksAfterShutdownPolicy, it is\"\n                + \" always false\");\n    }\n\n    /**\n     * {@inheritDoc}\n     */\n    @Override\n    public boolean getContinueExistingPeriodicTasksAfterShutdownPolicy() {\n        return false;\n    }\n\n    /**\n     * {@inheritDoc}\n     */\n    @Override\n    public void setExecuteExistingDelayedTasksAfterShutdownPolicy(boolean flag) {\n        throw new IllegalArgumentException(\"Not support to set executeExistingDelayedTasksAfterShutdownPolicy, it is\"\n                + \" always false\");","sourceCodeStart":181,"sourceCodeEnd":217,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-common/src/main/java/org/apache/pulsar/common/util/SingleThreadNonConcurrentFixedRateScheduler.java#L181-L217","documentation":"SingleThreadNonConcurrentFixedRateScheduler always behaves as if continueExistingPeriodicTasksAfterShutdownPolicy is false: after shutdown, periodic tasks are never continued. Therefore the inherited setContinueExistingPeriodicTasksAfterShutdownPolicy method unconditionally throws IllegalArgumentException to reject any attempt to change this fixed policy.","triggerScenarios":"Calling setContinueExistingPeriodicTasksAfterShutdownPolicy(true or false) on a SingleThreadNonConcurrentFixedRateScheduler instance, typically in code that configures a ScheduledExecutorService generically and applies this policy tuning call to any scheduler.","commonSituations":"Framework or utility code that customizes ScheduledExecutorService instances (e.g. copied ThreadPoolExecutor tuning snippets) invokes the setter on this custom scheduler; migration of code that used ScheduledThreadPoolExecutor to this Pulsar scheduler.","solutions":["Remove the call to setContinueExistingPeriodicTasksAfterShutdownPolicy; the scheduler intentionally never continues periodic tasks after shutdown.","Adjust generic scheduler-configuration code to skip this policy for this scheduler type (e.g. instanceof check or capability flag).","If post-shutdown execution of periodic tasks is required, use a plain ScheduledThreadPoolExecutor instead of this scheduler.","Handle the IllegalArgumentException defensively if the call site must stay source-compatible with multiple scheduler types."],"exampleFix":"// before\nscheduler.setContinueExistingPeriodicTasksAfterShutdownPolicy(true);\n// after\nif (!(scheduler instanceof SingleThreadNonConcurrentFixedRateScheduler)) {\n    scheduler.setContinueExistingPeriodicTasksAfterShutdownPolicy(true);\n}","handlingStrategy":"try-catch","validationCode":"static boolean supportsShutdownPolicies(java.util.concurrent.ScheduledExecutorService s) {\n    return !(s instanceof org.apache.pulsar.common.util.SingleThreadNonConcurrentFixedRateScheduler);\n}","typeGuard":"static boolean isPolicyConfigurable(java.util.concurrent.ScheduledExecutorService s) {\n    return s instanceof java.util.concurrent.ScheduledThreadPoolExecutor;\n}","tryCatchPattern":"try {\n    scheduler.setContinueExistingPeriodicTasksAfterShutdownPolicy(flag);\n} catch (IllegalArgumentException e) {\n    LOG.info(\"Scheduler {} does not support shutdown policy override: {}\", scheduler, e.getMessage());\n}","preventionTips":["Do not call shutdown-policy setters on SingleThreadNonConcurrentFixedRateScheduler — the policies are fixed to false","Gate generic executor-tuning code with instanceof ScheduledThreadPoolExecutor checks","If post-shutdown periodic execution is a requirement, choose ScheduledThreadPoolExecutor instead","Document in executor configuration utilities which policy calls are optional/unsupported"],"tags":["pulsar","scheduler","unsupported-operation","shutdown-policy"],"backgroundTag":"unsupported-scheduler-policy","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}