{"record":{"id":"3bd8459366d86cb0","repo":"apache/flink","slug":"cannot-have-more-than-streamingjobcountlimit-str","errorCode":null,"errorMessage":"Cannot have more than {streamingJobCountLimit} streaming jobs in a single environment.","messagePattern":"Cannot have more than (.+?) streaming 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":280,"sourceCode":"        }\n        jobIdManager.updateJobId(streamGraph);\n        final JobClient jobClient = super.executeAsync(streamGraph);\n\n        if (!suppressSysout) {\n            System.out.println(\"Job has been submitted with JobID \" + jobClient.getJobID());\n        }\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,","sourceCodeStart":262,"sourceCodeEnd":298,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-clients/src/main/java/org/apache/flink/client/program/StreamContextEnvironment.java#L262-L298","documentation":"Thrown by StreamContextEnvironment when the number of streaming jobs submitted in a single environment exceeds the configured streamingJobCountLimit. This limit prevents unbounded job submission in application mode. The limit is passed into setAsContext and enforced per-environment via a counter incremented on each streaming executeAsync.","triggerScenarios":"Submitting more streaming jobs than the allowed limit within one StreamExecutionEnvironment in application mode. Each call to execute/executeAsync that produces a STREAMING job graph increments the counter; exceeding the limit throws FlinkRuntimeException.","commonSituations":"Application mode with a loop that submits many streaming jobs, or a program that calls execute() multiple times without using separate environments. The default limit is typically 1 for application mode unless configured higher.","solutions":["Increase the streaming job count limit via the relevant deployment configuration option.","Refactor to submit fewer streaming jobs per environment, or use separate environments.","If submitting multiple jobs is intended, use application mode with a configured limit (e.g., execution.attached or job-count settings).","Consolidate multiple DataStream pipelines into a single job using unions or side outputs."],"exampleFix":"// before: submitting many streaming jobs in a loop\nfor (Source source : sources) {\n    env.fromSource(source, ...).print();\n    env.execute(); // exceeds limit on 2nd iteration\n}\n\n// after: single job with unioned sources\nDataStream<?> combined = env.union(sources.stream()\n    .map(s -> env.fromSource(s, ...))\n    .collect(Collectors.toList()));\ncombined.print();\nenv.execute();","handlingStrategy":"validation","validationCode":"// before calling executeAsync, track streaming job count\nint streamingJobsPlanned = countStreamingPipelines();\nif (streamingJobsPlanned > configuredStreamingLimit) {\n    throw new IllegalStateException(\n        \"Planned streaming jobs (\" + streamingJobsPlanned\n        + \") exceed limit (\" + configuredStreamingLimit + \")\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    env.executeAsync(streamGraph);\n} catch (FlinkRuntimeException e) {\n    if (e.getMessage().contains(\"streaming jobs in a single environment\")) {\n        // increase limit or reduce job count\n    }\n    throw e;\n}","preventionTips":["Design application-mode jobs to submit a single streaming pipeline.","Configure the streaming job count limit if multiple streaming jobs are intentional.","Monitor execute() call counts in application code."],"tags":["stream-context-environment","job-limit","streaming","application-mode"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}