Ability to sleep a thread

Published in Articles

As we all know, Salesforce is the multi-tenant platform. It means that "sleep" method will never be officially released. However, sometimes there is such a need, but mainly for testing. But I warn you right away: I do not advise you to use this method in production code. If there is such a need, it would be better to rethink the solution architecture.

public class Thread {
  public static void sleep(Long milliseconds) {
    final Long endTime = System.now().getTime() + milliseconds; 
    while (System.now().getTime() < endTime) {}

Useful links:

Comments powered by CComment