# Difference between Thread.sleep() VS WebUI.delay()

**URL:** <https://forum.katalon.com/t/difference-between-thread-sleep-vs-webui-delay/34120>\
**Category:** Web Testing\
**Tags:** katalon-studio\
**Created:** [October 3, 2019, 9:21am UTC](https://forum.katalon.com/t/difference-between-thread-sleep-vs-webui-delay/34120 "2019-10-03T09:21:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![apple-xn92](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/apple-xn92/32/8392_2.png) [@apple-xn92](https://forum.katalon.com/u/apple-xn92)\
**Post date:** [October 3, 2019, 9:21am UTC](https://forum.katalon.com/t/difference-between-thread-sleep-vs-webui-delay/34120/1 "2019-10-03T09:21:43Z")

</div>

Difference between Thread.sleep() VS WebUI.delay()

When do I use Thread.sleep() ? And, when do I use WebUI.delay() ?

---

<div class="post-metadata">

**Author:** ![discover.selenium](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/discover.selenium/32/522_2.png) [@discover.selenium](https://forum.katalon.com/u/discover.selenium)\
**Post date:** [October 3, 2019, 9:46am UTC](https://forum.katalon.com/t/difference-between-thread-sleep-vs-webui-delay/34120/2 "2019-10-03T09:46:51Z")

</div>

Both Method serves the same purpose. So it’s upto you.

Thread.sleep() method can be used to pause the execution of current thread for specified time in milliseconds.

**Thread.sleep(2000);** // Meaning Script will pause for 2 seconds.

**[WebUI.delay(2)](https://docs.katalon.com/katalon-studio/docs/common-delay.html#example)**  
//Delay the execution for 2 seconds. Thiis is a inbuilt keyword in Katalon for web testing

---

<div class="post-metadata">

**Author:** ![Ibus](https://avatars.discourse-cdn.com/v4/letter/i/e9a140/32.png) [@Ibus](https://forum.katalon.com/u/Ibus)\
**Post date:** [October 3, 2019, 10:25am UTC](https://forum.katalon.com/t/difference-between-thread-sleep-vs-webui-delay/34120/3 "2019-10-03T10:25:14Z")

</div>

> [@discover.selenium](#):
>
> Both Method serves the same purpose

this may be true **only** in single threading context.  
when multithreading programming is used, and particularly if inter-process communication is desired … those two methods will behave totaly different.  
just saying …

thread.sleep will suspend the thread for the given time … not pausing it. once resumed will continue exactly from where he was suspended.

using delay, thread is still active, but paused.

---

<div class="post-metadata">

**Author:** ![alexaminar-SUSPENDED](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/alexaminar-suspended/32/16104_2.png) [@alexaminar-SUSPENDED](https://forum.katalon.com/u/alexaminar-SUSPENDED)\
**Post date:** [August 10, 2021, 7:22am UTC](https://forum.katalon.com/t/difference-between-thread-sleep-vs-webui-delay/34120/4 "2021-08-10T07:22:42Z")

</div>

> [@apple-xn92](#):
>
> When do I use Thread.sleep() ?

[Python sleep()](http://net-informations.com/python/pro/sleep.htm) will pause for an hour, day or whatever if given the proper value. It does not allow other processes take place (in same script) however. A better way is to use an event which will create an event on timeout.
