<br />
<b>Warning</b>:  Undefined array key "global_protection_id" in <b>/home/wikitechy/public_html/interview-questions/wp-content/plugins/content-protector/inc/class-ps-rest-handler.php</b> on line <b>51</b><br />
{"id":681,"date":"2021-07-17T08:21:15","date_gmt":"2021-07-17T08:21:15","guid":{"rendered":"https:\/\/www.wikitechy.com\/interview-questions\/?p=681"},"modified":"2022-04-29T07:31:26","modified_gmt":"2022-04-29T07:31:26","slug":"difference-between-wait-and-sleep-in-java","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/interview-questions\/java\/difference-between-wait-and-sleep-in-java\/","title":{"rendered":"Difference between wait() and sleep() in java ?"},"content":{"rendered":"<div class=\"TextHeading\">\n<div class=\"hddn\">\n<h2 id=\"difference-between-wait-and-sleep-in-java\" class=\"color-pink\">Difference between\u00a0<a href=\"https:\/\/forums.wikitechy.com\/question\/what-are-the-differences-between-wait-and-sleep\/\" target=\"_blank\" rel=\"noopener\">wait() and sleep()<\/a>\u00a0in java ?<\/h2>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone size-full wp-image-4206\" src=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2021\/07\/difference-between-wait-and-sleep-in-java.png\" alt=\"\" width=\"850\" height=\"475\" srcset=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2021\/07\/difference-between-wait-and-sleep-in-java.png 850w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2021\/07\/difference-between-wait-and-sleep-in-java-300x168.png 300w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2021\/07\/difference-between-wait-and-sleep-in-java-768x429.png 768w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2021\/07\/difference-between-wait-and-sleep-in-java-390x218.png 390w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2021\/07\/difference-between-wait-and-sleep-in-java-820x458.png 820w\" sizes=\"(max-width: 850px) 100vw, 850px\" \/><\/p>\n<\/div>\n<\/div>\n<div class=\"table-responsive\">\n<table class=\"table-bordered table-striped table table-responsive\">\n<tbody>\n<tr>\n<th>Wait() Method<\/th>\n<th>Sleep() Method<\/th>\n<\/tr>\n<tr>\n<td class=\"text-leftalign\">wait() Method of\u00a0<a href=\"https:\/\/www.wikitechy.com\/tutorials\/java\/java-thread\" target=\"_blank\" rel=\"noopener\">thread<\/a>\u00a0class goes in waiting state<br \/>\nand it won\u2019t come back automatically until<br \/>\nwe call the notify() or notifyAll().<\/td>\n<td class=\"text-leftalign\"><a href=\"https:\/\/www.wikitechy.com\/tutorials\/java\/thread-sleep-java\">sleep()<\/a>\u00a0is a method which is used to pause the process for few seconds or the time we want too.<\/td>\n<\/tr>\n<tr>\n<td class=\"text-leftalign\">It is called on Object.<\/td>\n<td class=\"text-leftalign\">It is called on Threads.<\/td>\n<\/tr>\n<tr>\n<td class=\"text-leftalign\">It is an instant member of java.lang.Object class.<\/td>\n<td class=\"text-leftalign\">It is a static member of java.lang.Thread class.<\/td>\n<\/tr>\n<tr>\n<td class=\"text-leftalign\">wait() releases the lock or monitor.<\/td>\n<td class=\"text-leftalign\">sleep() doesn\u2019t releases the lock or monitor while waiting.<\/td>\n<\/tr>\n<tr>\n<td class=\"text-leftalign\">wait() is used for inter-thread communication.<\/td>\n<td class=\"text-leftalign\">sleep() is used to introduce pause on execution, generally.<\/td>\n<\/tr>\n<tr>\n<td class=\"text-leftalign\">It must be called within the synchronized blocks.<\/td>\n<td class=\"text-leftalign\">It may be called from within or outside the synchronized block.<\/td>\n<\/tr>\n<tr>\n<td class=\"text-leftalign\">\n<h3 id=\"wait-example\">wait() Example<\/h3>\n<pre> synchronized(LOCK)\r\n   {  \r\n      LOCK.wait(); \/\/ LOCK is not held\r\n   }<\/pre>\n<\/td>\n<td class=\"text-leftalign\">\n<h3 id=\"sleep-example\">sleep() Example<\/h3>\n<pre>    synchronized(LOCK)\r\n{  \r\n     Thread.sleep(1000); \/\/ LOCK is held\r\n}<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p><img decoding=\"async\" class=\"alignnone wp-image-4207 size-full\" src=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2021\/07\/sleep-and-wait-in-java.png\" alt=\"\" width=\"1920\" height=\"1080\" srcset=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2021\/07\/sleep-and-wait-in-java.png 1920w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2021\/07\/sleep-and-wait-in-java-300x169.png 300w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2021\/07\/sleep-and-wait-in-java-1024x576.png 1024w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2021\/07\/sleep-and-wait-in-java-768x432.png 768w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2021\/07\/sleep-and-wait-in-java-1536x864.png 1536w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2021\/07\/sleep-and-wait-in-java-390x219.png 390w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2021\/07\/sleep-and-wait-in-java-820x461.png 820w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2021\/07\/sleep-and-wait-in-java-1180x664.png 1180w\" sizes=\"(max-width: 1920px) 100vw, 1920px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Answer : wait() Method of thread class goes in waiting state &#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"passster_activate_protection":false,"passster_protect_child_pages":"","passster_protection_type":"password","passster_password":"","passster_activate_overwrite_defaults":"","passster_headline":"","passster_instruction":"","passster_placeholder":"","passster_button":"","passster_id":"","passster_activate_misc_settings":"","passster_redirect_url":"","passster_hide":"no","passster_area_shortcode":"","gtb_hide_title":false,"gtb_wrap_title":false,"gtb_class_title":"","gtb_remove_headerfooter":false,"footnotes":""},"categories":[4004],"tags":[195,491,360,203,199,214,198,363,209,4399,205,4394,4390,4398,4395,4401,4387,4386,4400,2936,222,4397,196,212,213,15933,4403,4396,286,207,366,204,217,282,4023,483,206,200,4388,197,280,4389,364,4402,4391,4392,4393,968,4404],"class_list":["post-681","post","type-post","status-publish","format-standard","hentry","category-java","tag-accenture-interview-questions-and-answers","tag-applied-materials-interview-questions-and-answers","tag-atos-interview-questions-and-answers","tag-capgemini-interview-questions-and-answers","tag-casting-networks-india-pvt-limited-interview-questions-and-answers","tag-cgi-group-inc-interview-questions-and-answers","tag-chetu-interview-questions-and-answers","tag-ciena-corporation-interview-questions-and-answers","tag-collabera-technologies-interview-questions-and-answers","tag-compare-the-sleep-and-wait-methods-in-java","tag-dell-international-services-india-pvt-ltd-interview-questions-and-answers","tag-difference-between-sleep-and-wait","tag-difference-between-sleep-and-wait-in-java-with-example","tag-difference-between-sleep-and-wait-in-selenium","tag-difference-between-sleep-and-yield","tag-difference-between-sleep1000-and-wait1000","tag-difference-between-wait-and-sleep","tag-difference-between-wait-and-sleep-in-java","tag-difference-between-wait-sleep-and-join-in-java","tag-fis-global-business-solutions-india-pvt-ltd-interview-questions-and-answers","tag-flipkart-interview-questions-and-answers","tag-how-to-use-wait-in-java","tag-ibm-interview-questions-and-answers","tag-indecomm-global-services-interview-questions-and-answers","tag-infosys-technologies-interview-questions-and-answers","tag-infozech-interview-questions-and-answers","tag-java-8-thread-sleep","tag-java-wait-example","tag-lt-infotech-interview-questions-and-answers","tag-mphasis-interview-questions-and-answers","tag-netapp-interview-questions-and-answers","tag-oracle-corporation-interview-questions-and-answers","tag-peoplestrong-interview-questions-and-answers","tag-persistent-systems-interview-questions-and-answers","tag-rbs-india-de-interview-questions-and-answers","tag-reliance-industries-ltd-interview-questions-and-answers","tag-sap-labs-india-pvt-ltd-interview-questions-and-answers","tag-tech-mahindra-interview-questions-and-answers","tag-thread-sleep-and-wait","tag-unitedhealth-group-interview-questions-and-answers","tag-virtusa-consulting-services-pvt-ltd-interview-questions-and-answers","tag-wait-and-sleep-in-java","tag-wells-fargo-interview-questions-and-answers","tag-what-happens-if-sleep-and-wait-executes-in-synchronized-block","tag-what-is-difference-between-wait-and-sleep-method","tag-what-is-wait-in-java","tag-what-is-yield-and-sleep-in-thread-java","tag-wipro-infotech-interview-questions-and-answers","tag-yield-method-in-java"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Difference between wait() and sleep() in java ? - Java<\/title>\n<meta name=\"description\" content=\"Difference between wait() and sleep() in java ? - wait() Method of thread class goes in waiting state and it won\u2019t come back automatically until we call the notify()\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wikitechy.com\/interview-questions\/java\/difference-between-wait-and-sleep-in-java\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Difference between wait() and sleep() in java ? - Java\" \/>\n<meta property=\"og:description\" content=\"Difference between wait() and sleep() in java ? - wait() Method of thread class goes in waiting state and it won\u2019t come back automatically until we call the notify()\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wikitechy.com\/interview-questions\/java\/difference-between-wait-and-sleep-in-java\/\" \/>\n<meta property=\"og:site_name\" content=\"Wikitechy\" \/>\n<meta property=\"article:published_time\" content=\"2021-07-17T08:21:15+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-04-29T07:31:26+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2021\/07\/difference-between-wait-and-sleep-in-java.png\" \/>\n<meta name=\"author\" content=\"Editor\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Editor\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/java\/difference-between-wait-and-sleep-in-java\/\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/java\/difference-between-wait-and-sleep-in-java\/\",\"name\":\"Difference between wait() and sleep() in java ? - Java\",\"isPartOf\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/java\/difference-between-wait-and-sleep-in-java\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/java\/difference-between-wait-and-sleep-in-java\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2021\/07\/difference-between-wait-and-sleep-in-java.png\",\"datePublished\":\"2021-07-17T08:21:15+00:00\",\"dateModified\":\"2022-04-29T07:31:26+00:00\",\"author\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/4d5a581fb5470d1560324bddc5e8b757\"},\"description\":\"Difference between wait() and sleep() in java ? - wait() Method of thread class goes in waiting state and it won\u2019t come back automatically until we call the notify()\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wikitechy.com\/interview-questions\/java\/difference-between-wait-and-sleep-in-java\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/java\/difference-between-wait-and-sleep-in-java\/#primaryimage\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2021\/07\/difference-between-wait-and-sleep-in-java.png\",\"contentUrl\":\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2021\/07\/difference-between-wait-and-sleep-in-java.png\",\"width\":850,\"height\":475},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#website\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/\",\"name\":\"Wikitechy\",\"description\":\"Interview Questions\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wikitechy.com\/interview-questions\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/4d5a581fb5470d1560324bddc5e8b757\",\"name\":\"Editor\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/e9531079fe7e07841b7b156c04d65e5f39d4adfd18b6ffe3edfff8ca5aab85b5?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/e9531079fe7e07841b7b156c04d65e5f39d4adfd18b6ffe3edfff8ca5aab85b5?s=96&d=mm&r=g\",\"caption\":\"Editor\"},\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/author\/editor\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Difference between wait() and sleep() in java ? - Java","description":"Difference between wait() and sleep() in java ? - wait() Method of thread class goes in waiting state and it won\u2019t come back automatically until we call the notify()","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wikitechy.com\/interview-questions\/java\/difference-between-wait-and-sleep-in-java\/","og_locale":"en_US","og_type":"article","og_title":"Difference between wait() and sleep() in java ? - Java","og_description":"Difference between wait() and sleep() in java ? - wait() Method of thread class goes in waiting state and it won\u2019t come back automatically until we call the notify()","og_url":"https:\/\/www.wikitechy.com\/interview-questions\/java\/difference-between-wait-and-sleep-in-java\/","og_site_name":"Wikitechy","article_published_time":"2021-07-17T08:21:15+00:00","article_modified_time":"2022-04-29T07:31:26+00:00","og_image":[{"url":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2021\/07\/difference-between-wait-and-sleep-in-java.png"}],"author":"Editor","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Editor","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wikitechy.com\/interview-questions\/java\/difference-between-wait-and-sleep-in-java\/","url":"https:\/\/www.wikitechy.com\/interview-questions\/java\/difference-between-wait-and-sleep-in-java\/","name":"Difference between wait() and sleep() in java ? - Java","isPartOf":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/java\/difference-between-wait-and-sleep-in-java\/#primaryimage"},"image":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/java\/difference-between-wait-and-sleep-in-java\/#primaryimage"},"thumbnailUrl":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2021\/07\/difference-between-wait-and-sleep-in-java.png","datePublished":"2021-07-17T08:21:15+00:00","dateModified":"2022-04-29T07:31:26+00:00","author":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/4d5a581fb5470d1560324bddc5e8b757"},"description":"Difference between wait() and sleep() in java ? - wait() Method of thread class goes in waiting state and it won\u2019t come back automatically until we call the notify()","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wikitechy.com\/interview-questions\/java\/difference-between-wait-and-sleep-in-java\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.wikitechy.com\/interview-questions\/java\/difference-between-wait-and-sleep-in-java\/#primaryimage","url":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2021\/07\/difference-between-wait-and-sleep-in-java.png","contentUrl":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2021\/07\/difference-between-wait-and-sleep-in-java.png","width":850,"height":475},{"@type":"WebSite","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website","url":"https:\/\/www.wikitechy.com\/interview-questions\/","name":"Wikitechy","description":"Interview Questions","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wikitechy.com\/interview-questions\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/4d5a581fb5470d1560324bddc5e8b757","name":"Editor","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/e9531079fe7e07841b7b156c04d65e5f39d4adfd18b6ffe3edfff8ca5aab85b5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e9531079fe7e07841b7b156c04d65e5f39d4adfd18b6ffe3edfff8ca5aab85b5?s=96&d=mm&r=g","caption":"Editor"},"url":"https:\/\/www.wikitechy.com\/interview-questions\/author\/editor\/"}]}},"_links":{"self":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/681","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/comments?post=681"}],"version-history":[{"count":3,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/681\/revisions"}],"predecessor-version":[{"id":4208,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/681\/revisions\/4208"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/media?parent=681"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/categories?post=681"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/tags?post=681"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}