apache/flink · error · FlinkRuntimeException
Cannot have more than {jobCountLimit} jobs in a single envir
Error message
Cannot have more than {jobCountLimit} jobs in a single environment. What it means
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.
Source
Thrown at flink-clients/src/main/java/org/apache/flink/client/program/StreamContextEnvironment.java:286
}
return jobClient;
}
private void validateAllowedExecution(StreamGraph streamGraph) {
if (streamGraph.getJobType() == JobType.STREAMING) {
streamingJobCount++;
}
jobCount++;
if (streamingJobCount > streamingJobCountLimit) {
throw new FlinkRuntimeException(
"Cannot have more than "
+ streamingJobCountLimit
+ " streaming jobs in a single environment.");
}
if (jobCount > jobCountLimit) {
throw new FlinkRuntimeException(
"Cannot have more than " + jobCountLimit + " jobs in a single environment.");
}
}
// --------------------------------------------------------------------------------------------
public static void setAsContext(
final PipelineExecutorServiceLoader executorServiceLoader,
final Configuration clusterConfiguration,
final ClassLoader userCodeClassLoader,
final int jobCountLimit,
final int streamingJobCountLimit,
final boolean suppressSysout,
@Nullable final ApplicationID applicationId,
@Nullable final JarInfo userJarInfo,
Collection<JobInfo> allRecoveredJobInfos) {
final StreamExecutionEnvironmentFactory factory =
envInitConfig -> {View on GitHub (pinned to 2f3c205e92)
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.
Example fix
// before: multiple execute calls
for (int i = 0; i < 10; i++) {
env.fromCollection(data.get(i)).print();
env.execute("job-" + i); // exceeds jobCountLimit
}
// after: single job
DataStream<String> all = env.fromCollection(flatData);
all.print();
env.execute("single-job"); Defensive patterns
Strategy: validation
Validate before calling
// before calling executeAsync, track total job count
int totalJobsPlanned = countAllExecuteCalls();
if (totalJobsPlanned > configuredJobLimit) {
throw new IllegalStateException(
"Planned jobs (" + totalJobsPlanned
+ ") exceed limit (" + configuredJobLimit + ")");
} Try / catch
try {
env.executeAsync(streamGraph);
} catch (FlinkRuntimeException e) {
if (e.getMessage().contains("jobs in a single environment")) {
// increase job count limit or reduce execute() calls
}
throw e;
} Prevention
- 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.
When it happens
Trigger: Submitting more total jobs than the jobCountLimit in one environment. Each executeAsync increments jobCount regardless of job type; exceeding the limit throws FlinkRuntimeException.
Common situations: 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.
Related errors
- Cannot have more than {streamingJobCountLimit} streaming job
- Application Mode not supported by standalone deployments.
- Could not create the Dispatcher rpc endpoint.
- Invalid cluster id "%s". The expected format is [0-9a-fA-F]{
- Could not execute application.
AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14).
Data as JSON: /api/errors/8013b7c09e23fcb3.
Report an issue: GitHub.