---
schema_version: "1"
id: f436ff944a92243a314660001d551b23c0a5921c953aa4762d41c02a55821ea5
title: "ApexGuru Antipattern: Busy Loop Delay"
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/xcloud/264-0-0/apexguru_antipattern_busy_loop_delay.md
canonical_url: https://help.salesforce.com/s/articleView?id=xcloud.apexguru_antipattern_busy_loop_delay.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 536b5d442380dd4ec3a2a975d095b5f9f88a07fff88ae64547209333a772f2ea
description: Busy loops that introduce a delay aren’t efficient and lead to performance issues. They waste CPU resources due to continuous loop execution. Governor limit breaches cause transaction failures. For delayed execution, use Salesforce alternatives like scheduling systems in Apex. If the delay is due to an async job, use System.enqueueJob with a delay parameter.
products:
  - Cross Cloud
release: "264"
---
# ApexGuru Antipattern: Busy Loop Delay

Busy loops that introduce a delay aren’t efficient and lead to performance issues. They waste CPU resources due to continuous loop execution. Governor limit breaches cause transaction failures. For delayed execution, use Salesforce alternatives like scheduling systems in Apex. If the delay is due to an async job, use System.enqueueJob with a delay parameter.

## Scope

Detection only

## Detection Example

```java
Apex
public class JobScheduler {
    public void scheduleJobWithDelay() {
        Integer delayTime = 10; // Delay in seconds
        DateTime startTime = System.now();        
        // Busy loop to create a delay
        while (System.now() < startTime.addSeconds(delayTime)) {
            // Do nothing (busy wait)
        }     
        // Enqueue the Queueable job after the delay
        ID jobId = System.enqueueJob(new MyQueueableJob());
    }
}
```