{"id":1555,"date":"2021-05-21T13:39:41","date_gmt":"2021-05-21T07:54:41","guid":{"rendered":"https:\/\/bcisnotes.com\/secondsemester\/?p=1555"},"modified":"2021-05-21T13:39:41","modified_gmt":"2021-05-21T07:54:41","slug":"what-is-multithreading-write-a-program-to-demonstrate","status":"publish","type":"post","link":"https:\/\/bcisnotes.com\/secondsemester\/q-a\/what-is-multithreading-write-a-program-to-demonstrate\/","title":{"rendered":"What is multithreading? Write a program to demonstrate create the thread in java."},"content":{"rendered":"<h1 style=\"text-align: center;\">What is multithreading? Write a program to demonstrate create the thread in java.<\/h1>\n<p>The answer to the question &#8220;<em>What is multithreading? Write a program to demonstrate create the thread in java.<\/em>&#8221; is given below:<\/p>\n<p>Multithreading in Java is a process of executing multiple threads simultaneously. A thread is a lightweight sub-process, the smallest unit of processing. Multiprocessing and multithreading, both are used to achieve multitasking. However, we use multithreading than multiprocessing because threads use a shared memory area. They don&#8217;t allocate separate memory area so saves memory, and context-switching between the threads takes less time than process.<\/p>\n<p>Java Multithreading is mostly used in games, animation, etc.<\/p>\n<p>Thread class provide constructors and methods to create and perform operations on a thread. Thread class extends Object class and implements Runnable interface.<\/p>\n<p>class ThreadDemo implements Runnable {<br \/>\nThread t;<br \/>\nThreadDemo() {<br \/>\nt = new Thread(this, &#8220;Thread&#8221;);<br \/>\nSystem.out.println(&#8220;C thread: &#8221; + t);<br \/>\nt.start();<br \/>\n}<br \/>\npublic void run() {<br \/>\ntry {<br \/>\nSystem.out.println(&#8220;C Thread&#8221;);<br \/>\nThread.sleep(50);<br \/>\n} catch (InterruptedException e) {<br \/>\nSystem.out.println(&#8220;The C thread is interrupted.&#8221;);<br \/>\n}<br \/>\nSystem.out.println(&#8220;Exiting the C thread&#8221;);<br \/>\n}<br \/>\n}<br \/>\npublic class Demo {<br \/>\npublic static void main(String args[]) {<br \/>\nnew ThreadDemo();<br \/>\ntry {<br \/>\nSystem.out.println(&#8220;M Thread&#8221;);<br \/>\nThread.sleep(100);<br \/>\n} catch (InterruptedException e) {<br \/>\nSystem.out.println(&#8220;The M thread is interrupted&#8221;);<br \/>\n}<br \/>\nSystem.out.println(&#8220;Exiting the M thread&#8221;);<br \/>\n}<br \/>\n}<\/p>\n<p>You may also like\u00a0<a href=\"https:\/\/bcisnotes.com\/secondsemester\/question-bank\/pokhara-university-2016-fall-object-oriented-language-bcis\/\">Pokhara University, 2016 Fall Object Oriented Language<\/a><\/p>\n<div class=\"pzvni69f7fbfb39b50\" ><div id=\"amzn-assoc-ad-668fe681-bdc6-49ee-a9f9-a4c2f5be29a0\"><\/div><script async src=\"\/\/z-na.amazon-adsystem.com\/widgets\/onejs?MarketPlace=US&adInstanceId=668fe681-bdc6-49ee-a9f9-a4c2f5be29a0\"><\/script><\/div><style type=\"text\/css\">\r\n@media screen and (min-width: 1201px) {\r\n.pzvni69f7fbfb39b50 {\r\ndisplay: block;\r\n}\r\n}\r\n@media screen and (min-width: 993px) and (max-width: 1200px) {\r\n.pzvni69f7fbfb39b50 {\r\ndisplay: block;\r\n}\r\n}\r\n@media screen and (min-width: 769px) and (max-width: 992px) {\r\n.pzvni69f7fbfb39b50 {\r\ndisplay: block;\r\n}\r\n}\r\n@media screen and (min-width: 768px) and (max-width: 768px) {\r\n.pzvni69f7fbfb39b50 {\r\ndisplay: block;\r\n}\r\n}\r\n@media screen and (max-width: 767px) {\r\n.pzvni69f7fbfb39b50 {\r\ndisplay: block;\r\n}\r\n}\r\n<\/style>\r\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>What is multithreading? Write a program to demonstrate create the thread in java. The answer to the question &#8220;What is multithreading? Write a program to <a class=\"mh-excerpt-more\" href=\"https:\/\/bcisnotes.com\/secondsemester\/q-a\/what-is-multithreading-write-a-program-to-demonstrate\/\" title=\"What is multithreading? Write a program to demonstrate create the thread in java.\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":14,"featured_media":1557,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v23.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>What is multithreading? Write a program to demonstrate<\/title>\n<meta name=\"description\" content=\"The answer to the question &quot;What is multithreading? Write a program to demonstrate create the thread in java.&quot; is given below:\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/bcisnotes.com\/secondsemester\/q-a\/what-is-multithreading-write-a-program-to-demonstrate\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What is multithreading? Write a program to demonstrate\" \/>\n<meta property=\"og:description\" content=\"The answer to the question &quot;What is multithreading? Write a program to demonstrate create the thread in java.&quot; is given below:\" \/>\n<meta property=\"og:url\" content=\"https:\/\/bcisnotes.com\/secondsemester\/q-a\/what-is-multithreading-write-a-program-to-demonstrate\/\" \/>\n<meta property=\"og:site_name\" content=\"BCIS NOTES\" \/>\n<meta property=\"article:published_time\" content=\"2021-05-21T07:54:41+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/bcisnotes.com\/secondsemester\/wp-content\/uploads\/2021\/05\/fall-2016-.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"340\" \/>\n\t<meta property=\"og:image:height\" content=\"230\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Satyal\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Satyal\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/bcisnotes.com\/secondsemester\/q-a\/what-is-multithreading-write-a-program-to-demonstrate\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/bcisnotes.com\/secondsemester\/q-a\/what-is-multithreading-write-a-program-to-demonstrate\/\"},\"author\":{\"name\":\"Satyal\",\"@id\":\"https:\/\/bcisnotes.com\/secondsemester\/#\/schema\/person\/f8dbec6a3775d3a538119e749a62cea8\"},\"headline\":\"What is multithreading? Write a program to demonstrate create the thread in java.\",\"datePublished\":\"2021-05-21T07:54:41+00:00\",\"dateModified\":\"2021-05-21T07:54:41+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/bcisnotes.com\/secondsemester\/q-a\/what-is-multithreading-write-a-program-to-demonstrate\/\"},\"wordCount\":239,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/bcisnotes.com\/secondsemester\/#organization\"},\"image\":{\"@id\":\"https:\/\/bcisnotes.com\/secondsemester\/q-a\/what-is-multithreading-write-a-program-to-demonstrate\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/bcisnotes.com\/secondsemester\/wp-content\/uploads\/2021\/05\/fall-2016-.jpg\",\"articleSection\":[\"Q\/A\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/bcisnotes.com\/secondsemester\/q-a\/what-is-multithreading-write-a-program-to-demonstrate\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/bcisnotes.com\/secondsemester\/q-a\/what-is-multithreading-write-a-program-to-demonstrate\/\",\"url\":\"https:\/\/bcisnotes.com\/secondsemester\/q-a\/what-is-multithreading-write-a-program-to-demonstrate\/\",\"name\":\"What is multithreading? Write a program to demonstrate\",\"isPartOf\":{\"@id\":\"https:\/\/bcisnotes.com\/secondsemester\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/bcisnotes.com\/secondsemester\/q-a\/what-is-multithreading-write-a-program-to-demonstrate\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/bcisnotes.com\/secondsemester\/q-a\/what-is-multithreading-write-a-program-to-demonstrate\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/bcisnotes.com\/secondsemester\/wp-content\/uploads\/2021\/05\/fall-2016-.jpg\",\"datePublished\":\"2021-05-21T07:54:41+00:00\",\"dateModified\":\"2021-05-21T07:54:41+00:00\",\"description\":\"The answer to the question \\\"What is multithreading? Write a program to demonstrate create the thread in java.\\\" is given below:\",\"breadcrumb\":{\"@id\":\"https:\/\/bcisnotes.com\/secondsemester\/q-a\/what-is-multithreading-write-a-program-to-demonstrate\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/bcisnotes.com\/secondsemester\/q-a\/what-is-multithreading-write-a-program-to-demonstrate\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/bcisnotes.com\/secondsemester\/q-a\/what-is-multithreading-write-a-program-to-demonstrate\/#primaryimage\",\"url\":\"https:\/\/bcisnotes.com\/secondsemester\/wp-content\/uploads\/2021\/05\/fall-2016-.jpg\",\"contentUrl\":\"https:\/\/bcisnotes.com\/secondsemester\/wp-content\/uploads\/2021\/05\/fall-2016-.jpg\",\"width\":340,\"height\":230,\"caption\":\"What is multithreading\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/bcisnotes.com\/secondsemester\/q-a\/what-is-multithreading-write-a-program-to-demonstrate\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/bcisnotes.com\/secondsemester\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"What is multithreading? Write a program to demonstrate create the thread in java.\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/bcisnotes.com\/secondsemester\/#website\",\"url\":\"https:\/\/bcisnotes.com\/secondsemester\/\",\"name\":\"BCIS NOTES\",\"description\":\"Second Semester\",\"publisher\":{\"@id\":\"https:\/\/bcisnotes.com\/secondsemester\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/bcisnotes.com\/secondsemester\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/bcisnotes.com\/secondsemester\/#organization\",\"name\":\"BCIS NOTES\",\"url\":\"https:\/\/bcisnotes.com\/secondsemester\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/bcisnotes.com\/secondsemester\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/bcisnotes.com\/secondsemester\/wp-content\/uploads\/2019\/12\/cropped-2.jpg\",\"contentUrl\":\"https:\/\/bcisnotes.com\/secondsemester\/wp-content\/uploads\/2019\/12\/cropped-2.jpg\",\"width\":300,\"height\":100,\"caption\":\"BCIS NOTES\"},\"image\":{\"@id\":\"https:\/\/bcisnotes.com\/secondsemester\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/bcisnotes.com\/secondsemester\/#\/schema\/person\/f8dbec6a3775d3a538119e749a62cea8\",\"name\":\"Satyal\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/bcisnotes.com\/secondsemester\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/046e4cf5c1f258099878dc90092445b4?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/046e4cf5c1f258099878dc90092445b4?s=96&d=mm&r=g\",\"caption\":\"Satyal\"},\"sameAs\":[\"http:\/\/bcisnotes.com\/secondsemester\"],\"url\":\"https:\/\/bcisnotes.com\/secondsemester\/author\/sadikshya\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"What is multithreading? Write a program to demonstrate","description":"The answer to the question \"What is multithreading? Write a program to demonstrate create the thread in java.\" is given below:","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:\/\/bcisnotes.com\/secondsemester\/q-a\/what-is-multithreading-write-a-program-to-demonstrate\/","og_locale":"en_US","og_type":"article","og_title":"What is multithreading? Write a program to demonstrate","og_description":"The answer to the question \"What is multithreading? Write a program to demonstrate create the thread in java.\" is given below:","og_url":"https:\/\/bcisnotes.com\/secondsemester\/q-a\/what-is-multithreading-write-a-program-to-demonstrate\/","og_site_name":"BCIS NOTES","article_published_time":"2021-05-21T07:54:41+00:00","og_image":[{"width":340,"height":230,"url":"https:\/\/bcisnotes.com\/secondsemester\/wp-content\/uploads\/2021\/05\/fall-2016-.jpg","type":"image\/jpeg"}],"author":"Satyal","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Satyal","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/bcisnotes.com\/secondsemester\/q-a\/what-is-multithreading-write-a-program-to-demonstrate\/#article","isPartOf":{"@id":"https:\/\/bcisnotes.com\/secondsemester\/q-a\/what-is-multithreading-write-a-program-to-demonstrate\/"},"author":{"name":"Satyal","@id":"https:\/\/bcisnotes.com\/secondsemester\/#\/schema\/person\/f8dbec6a3775d3a538119e749a62cea8"},"headline":"What is multithreading? Write a program to demonstrate create the thread in java.","datePublished":"2021-05-21T07:54:41+00:00","dateModified":"2021-05-21T07:54:41+00:00","mainEntityOfPage":{"@id":"https:\/\/bcisnotes.com\/secondsemester\/q-a\/what-is-multithreading-write-a-program-to-demonstrate\/"},"wordCount":239,"commentCount":0,"publisher":{"@id":"https:\/\/bcisnotes.com\/secondsemester\/#organization"},"image":{"@id":"https:\/\/bcisnotes.com\/secondsemester\/q-a\/what-is-multithreading-write-a-program-to-demonstrate\/#primaryimage"},"thumbnailUrl":"https:\/\/bcisnotes.com\/secondsemester\/wp-content\/uploads\/2021\/05\/fall-2016-.jpg","articleSection":["Q\/A"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/bcisnotes.com\/secondsemester\/q-a\/what-is-multithreading-write-a-program-to-demonstrate\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/bcisnotes.com\/secondsemester\/q-a\/what-is-multithreading-write-a-program-to-demonstrate\/","url":"https:\/\/bcisnotes.com\/secondsemester\/q-a\/what-is-multithreading-write-a-program-to-demonstrate\/","name":"What is multithreading? Write a program to demonstrate","isPartOf":{"@id":"https:\/\/bcisnotes.com\/secondsemester\/#website"},"primaryImageOfPage":{"@id":"https:\/\/bcisnotes.com\/secondsemester\/q-a\/what-is-multithreading-write-a-program-to-demonstrate\/#primaryimage"},"image":{"@id":"https:\/\/bcisnotes.com\/secondsemester\/q-a\/what-is-multithreading-write-a-program-to-demonstrate\/#primaryimage"},"thumbnailUrl":"https:\/\/bcisnotes.com\/secondsemester\/wp-content\/uploads\/2021\/05\/fall-2016-.jpg","datePublished":"2021-05-21T07:54:41+00:00","dateModified":"2021-05-21T07:54:41+00:00","description":"The answer to the question \"What is multithreading? Write a program to demonstrate create the thread in java.\" is given below:","breadcrumb":{"@id":"https:\/\/bcisnotes.com\/secondsemester\/q-a\/what-is-multithreading-write-a-program-to-demonstrate\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/bcisnotes.com\/secondsemester\/q-a\/what-is-multithreading-write-a-program-to-demonstrate\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/bcisnotes.com\/secondsemester\/q-a\/what-is-multithreading-write-a-program-to-demonstrate\/#primaryimage","url":"https:\/\/bcisnotes.com\/secondsemester\/wp-content\/uploads\/2021\/05\/fall-2016-.jpg","contentUrl":"https:\/\/bcisnotes.com\/secondsemester\/wp-content\/uploads\/2021\/05\/fall-2016-.jpg","width":340,"height":230,"caption":"What is multithreading"},{"@type":"BreadcrumbList","@id":"https:\/\/bcisnotes.com\/secondsemester\/q-a\/what-is-multithreading-write-a-program-to-demonstrate\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/bcisnotes.com\/secondsemester\/"},{"@type":"ListItem","position":2,"name":"What is multithreading? Write a program to demonstrate create the thread in java."}]},{"@type":"WebSite","@id":"https:\/\/bcisnotes.com\/secondsemester\/#website","url":"https:\/\/bcisnotes.com\/secondsemester\/","name":"BCIS NOTES","description":"Second Semester","publisher":{"@id":"https:\/\/bcisnotes.com\/secondsemester\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/bcisnotes.com\/secondsemester\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/bcisnotes.com\/secondsemester\/#organization","name":"BCIS NOTES","url":"https:\/\/bcisnotes.com\/secondsemester\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/bcisnotes.com\/secondsemester\/#\/schema\/logo\/image\/","url":"https:\/\/bcisnotes.com\/secondsemester\/wp-content\/uploads\/2019\/12\/cropped-2.jpg","contentUrl":"https:\/\/bcisnotes.com\/secondsemester\/wp-content\/uploads\/2019\/12\/cropped-2.jpg","width":300,"height":100,"caption":"BCIS NOTES"},"image":{"@id":"https:\/\/bcisnotes.com\/secondsemester\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/bcisnotes.com\/secondsemester\/#\/schema\/person\/f8dbec6a3775d3a538119e749a62cea8","name":"Satyal","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/bcisnotes.com\/secondsemester\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/046e4cf5c1f258099878dc90092445b4?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/046e4cf5c1f258099878dc90092445b4?s=96&d=mm&r=g","caption":"Satyal"},"sameAs":["http:\/\/bcisnotes.com\/secondsemester"],"url":"https:\/\/bcisnotes.com\/secondsemester\/author\/sadikshya\/"}]}},"_links":{"self":[{"href":"https:\/\/bcisnotes.com\/secondsemester\/wp-json\/wp\/v2\/posts\/1555"}],"collection":[{"href":"https:\/\/bcisnotes.com\/secondsemester\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bcisnotes.com\/secondsemester\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bcisnotes.com\/secondsemester\/wp-json\/wp\/v2\/users\/14"}],"replies":[{"embeddable":true,"href":"https:\/\/bcisnotes.com\/secondsemester\/wp-json\/wp\/v2\/comments?post=1555"}],"version-history":[{"count":1,"href":"https:\/\/bcisnotes.com\/secondsemester\/wp-json\/wp\/v2\/posts\/1555\/revisions"}],"predecessor-version":[{"id":1556,"href":"https:\/\/bcisnotes.com\/secondsemester\/wp-json\/wp\/v2\/posts\/1555\/revisions\/1556"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/bcisnotes.com\/secondsemester\/wp-json\/wp\/v2\/media\/1557"}],"wp:attachment":[{"href":"https:\/\/bcisnotes.com\/secondsemester\/wp-json\/wp\/v2\/media?parent=1555"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bcisnotes.com\/secondsemester\/wp-json\/wp\/v2\/categories?post=1555"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bcisnotes.com\/secondsemester\/wp-json\/wp\/v2\/tags?post=1555"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}