How to pause execution for 5 seconds in Scala

2 Answers

0 votes
object PauseExecution {

  def main(args: Array[String]): Unit = {
    println("Execution paused for 5 seconds...") 
    
    Thread.sleep(5000)
    
    println("Resuming execution.")   
  }
}



/*
run:
   
Execution paused for 5 seconds...
Resuming execution.
 
*/

 



answered Apr 30, 2025 by avibootz
0 votes
import java.util.concurrent.TimeUnit

object PauseExecution {

  def main(args: Array[String]): Unit = {
    println("Execution paused for 5 seconds...") 

    TimeUnit.SECONDS.sleep(5)
    
    println("Resuming execution.")   
  }
}



/*
run:
   
Execution paused for 5 seconds...
Resuming execution.
 
*/

 



answered Apr 30, 2025 by avibootz

Related questions

1 answer 165 views
1 answer 164 views
1 answer 182 views
1 answer 139 views
139 views asked Apr 30, 2025 by avibootz
1 answer 162 views
2 answers 162 views
1 answer 147 views
...