{"record":{"id":"8013b7c09e23fcb3","repo":"apache/flink","slug":"cannot-have-more-than-jobcountlimit-jobs-in-a-si","errorCode":null,"errorMessage":"Cannot have more than {jobCountLimit} jobs in a single environment.","messagePattern":"Cannot have more than (.+?) jobs in a single environment\\.","errorType":"exception","errorClass":"FlinkRuntimeException","httpStatus":null,"severity":"error","filePath":"flink-clients/src/main/java/org/apache/flink/client/program/StreamContextEnvironment.java","lineNumber":286,"sourceCode":"        }\n\n        return jobClient;\n    }\n\n    private void validateAllowedExecution(StreamGraph streamGraph) {\n        if (streamGraph.getJobType() == JobType.STREAMING) {\n            streamingJobCount++;\n        }\n        jobCount++;\n\n        if (streamingJobCount > streamingJobCountLimit) {\n            throw new FlinkRuntimeException(\n                    \"Cannot have more than \"\n                            + streamingJobCountLimit\n                            + \" streaming jobs in a single environment.\");\n        }\n        if (jobCount > jobCountLimit) {\n            throw new FlinkRuntimeException(\n                    \"Cannot have more than \" + jobCountLimit + \" jobs in a single environment.\");\n        }\n    }\n\n    // --------------------------------------------------------------------------------------------\n\n    public static void setAsContext(\n            final PipelineExecutorServiceLoader executorServiceLoader,\n            final Configuration clusterConfiguration,\n            final ClassLoader userCodeClassLoader,\n            final int jobCountLimit,\n            final int streamingJobCountLimit,\n            final boolean suppressSysout,\n            @Nullable final ApplicationID applicationId,\n            @Nullable final JarInfo userJarInfo,\n            Collection<JobInfo> allRecoveredJobInfos) {\n        final StreamExecutionEnvironmentFactory factory =\n                envInitConfig -> {","sourceCodeStart":268,"sourceCodeEnd":304,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-clients/src/main/java/org/apache/flink/client/program/StreamContextEnvironment.java#L268-L304","documentation":"Thrown by StreamContextEnvironment when the total number of jobs (streaming or batch) submitted in a single environment exceeds the configured jobCountLimit. This is the overall job limit, distinct from the streaming-specific limit. Both limits are enforced in validateAllowedExecution on every executeAsync call.","triggerScenarios":"Submitting more total jobs than the jobCountLimit in one environment. Each executeAsync increments jobCount regardless of job type; exceeding the limit throws FlinkRuntimeException.","commonSituations":"Application mode with multiple execute() calls exceeding the configured total job limit. Common when migrating a session-mode workload that submitted many jobs into application mode without adjusting limits.","solutions":["Increase the job count limit via the deployment configuration if multiple jobs are intended.","Refactor to reduce the number of execute() calls — combine pipelines.","Use session mode if the use case inherently requires many independent jobs.","Review the application's job submission logic to ensure only intended jobs are submitted."],"exampleFix":"// before: multiple execute calls\nfor (int i = 0; i < 10; i++) {\n    env.fromCollection(data.get(i)).print();\n    env.execute(\"job-\" + i); // exceeds jobCountLimit\n}\n\n// after: single job\nDataStream<String> all = env.fromCollection(flatData);\nall.print();\nenv.execute(\"single-job\");","handlingStrategy":"validation","validationCode":"// before calling executeAsync, track total job count\nint totalJobsPlanned = countAllExecuteCalls();\nif (totalJobsPlanned > configuredJobLimit) {\n    throw new IllegalStateException(\n        \"Planned jobs (\" + totalJobsPlanned\n        + \") exceed limit (\" + configuredJobLimit + \")\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    env.executeAsync(streamGraph);\n} catch (FlinkRuntimeException e) {\n    if (e.getMessage().contains(\"jobs in a single environment\")) {\n        // increase job count limit or reduce execute() calls\n    }\n    throw e;\n}","preventionTips":["Minimize execute() calls per environment in application mode.","Set the job count limit configuration if multiple jobs are required.","Consider session mode for workloads with many independent jobs."],"tags":["stream-context-environment","job-limit","application-mode"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}