0

I wrote this class:

public with sharing class QueueTest1 implements Queueable, Finalizer{

    public QueueTest1(){
    }
    public void execute(FinalizerContext param1) {
        System.debug('param1 -> '+param1);
    }

    public void execute(QueueableContext param1) {
        while (true){

        }

    }
}

And used anonymous apex to executed this 4-5 times:

for (Integer i = 0; i < 50; i++) {
    System.enqueueJob(new QueueTest1());
}

I was able to see in Apex Jobs, there were 200 Queueable jobs queued with few statuses as Processing and few as Queued.

Now

And saw that Flex queue was still empty, as Queueable is not inserted to flex queue.

1. where does Queueable gets queued if not in flex Queue. Does that have any limit?

Also when I was refreshing screen of "Apex Jobs" I was able to see this error.

enter image description here

2. Is this because as there is an infinite loop in the my Queueable class, or because salesforce is trying to run more than 5 Queueables in a synchronous manner?

3. What happens to batch in the above scenario if the code tries to add a batch. Does it get added to FlexQueue, or it will get executed only after all Queued Queueables are finished, or will it get executed as soon as batch is executed?

1 Answer 1

0

where does Queueable gets queued if not in flex Queue. Does that have any limit?

It goes to the general Asynchronous Queue, along with @future and Batchable execution threads. There is a limit of 250,000 asynchronous calls per day, and, of course, you can only call up to 50 Queueables per transaction, but there are no other general limits regarding these jobs.

Is this because as there is an infinite loop in the my Queueable class, or because salesforce is trying to run more than 5 Queueables in a synchronous manner?

You have more than 10 synchronous transactions running for longer than 5 seconds. You shouldn't be getting this error for long-running Queueables, at least in theory. You may need to contact support for that. That said, you are creating long-running jobs, which will prevent other jobs from running in your org until those are done. Note that since you have infinite loops, they will eventually time out after about 60-65 seconds of total execution time.

What happens to batch in the above scenario if the code tries to add a batch. Does it get added to FlexQueue, or it will get executed only after all Queued Queueables are finished, or will it get executed as soon as batch is executed?

Since Queueables are not in the Flex Queue, it is free to execute as soon as there's a free slot available for it to run. Some of your Queueables may be pushed back as a result, as any time an org has more than a given threshold of jobs of one type, other orgs and jobs are given a chance to run. You really can't predict these sorts of things in advance, so the answer is a very definite "maybe."

Batchable classes do not go to the Flex Queue until there are five active running batches. Future and Queueable classes do not go in to the Flex Queue, nor do they influence the order or timing of those jobs directly. Only one start method is allowed to execute at a time, but up to five batch jobs may be running concurrently.

3
  • I may not be able to reach support team for my 2nd point as its my own trailhead org. And there are no synchronous jobs running in the system. It only comes up when I add some 150+ queueable with infinite executions and refresh the Apex Job screen. Based on error message I thought salesforce is trying to execute more than 10 Synchronous transactions on that page to show some details or something. As there is no other transactions running in the org. Commented Jul 7, 2021 at 6:02
  • @NagendraSingh The documentation says that only synchronous jobs should count. You'll have to check your debug logs, perhaps. I'll see if I can replicate this part and maybe get a bug logged. I've never seen it happen before, but it seems pretty easy to reproduce if it's an actual bug.
    – sfdcfox
    Commented Jul 7, 2021 at 6:08
  • Yes its easy to replicate, with the above code executed some 4-5 times, just refresh the apex job page for few times, and one of those times you will the error. Commented Jul 7, 2021 at 6:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .