{"id":31840,"date":"2023-01-25T01:37:03","date_gmt":"2023-01-24T20:07:03","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-java-uses-how-many-processors-available-in-os-closed\/"},"modified":"2023-01-25T01:37:03","modified_gmt":"2023-01-24T20:07:03","slug":"solved-java-uses-how-many-processors-available-in-os-closed","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-java-uses-how-many-processors-available-in-os-closed\/","title":{"rendered":"[Solved] Java uses how many processors available in OS? [closed]"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-17148053\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"17148053\" data-parentid=\"17147746\" data-score=\"0\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<blockquote>\n<p>If any OS is multi-processor, then JVM uses all of them or one of them?<\/p>\n<\/blockquote>\n<p>On most modern hardware architectures, the JVM will make use of all CPUs\/cores made available to it by the OS.<\/p>\n<blockquote>\n<p>And As processors ahve different memory context so their corresponding memory threads will also have different memory contexts, so they will not be having concurrency issues?<\/p>\n<\/blockquote>\n<p>Uh, no?  I&#8217;m not sure what you are asking here but the whole issue with concurrency is that CPUs have their own cache memory.  This is why memory synchronization and locking is so important.  A thread may make local changes to its cached memory or its cached memory may get invalidated because of changes made to central storage by other threads.  So there certainly are &#8220;concurrency issues&#8221; with multi-processor and different memory &#8220;contexts&#8221;.<\/p>\n<hr>\n<p>Edit:<\/p>\n<blockquote>\n<p>Here is the main doubt i have: If there are 4 processes being used by JVM (P1,P2,P3,P4) then threads running under one process will face concurrency issue, Thread T1 under P1, and thread T2 under P2 will never have concurrency issue as they have different memory contexts. Am i right or wrong?<\/p>\n<\/blockquote>\n<p>You are wrong.  The JVM will schedule your 4 user threads and the other background threads (gc, finalizer, jmx, etc) on the 4 processors in contention with other processes running on the same operating system.  At points in time, the JVM may be using all 4 processors or may be using no processors depending on the other processes running on the OS.<\/p>\n<p>If T1 and T2 are on different processors then they can be running simultaneously.  None of the threads will have concurrency issues unless they share data.  If T1 makes changes to an object that T2 is also using, T2 may or may not see these changes depending on what synchronization is being used.  This memory synchronization is one of the big problems with multi-threaded programming.  For example:<\/p>\n<pre><code> static Integer sharedValue = 1;\n ...\n \/\/ thread T1 changes the shared value\n sharedValue = 2;\n ...\n \/\/ thread T2 reads the shared value later\n \/\/ it is unknown whether this will print 1 or 2\n System.out.println(\"shared = \" + sharedValue);\n<\/code><\/pre>\n<p>If T2 is swapped out and T3 runs on the same processor there may actually be <em>less<\/em> concurrency issues since they are both using the same CPU cache but you still need to worry about <em>locking<\/em>.  For example, if the T2 task does a <code>++<\/code> which seems atomic but is actually 3 operations (get, increment, store), it might get interrupted after the increment but before the store and may overwrite T3&#8217;s increment:<\/p>\n<pre><code> static int counter = 0;\n ...\n \/\/ thread T2\n \/\/ 3 operations: get, increment, store\n \/\/ this thread might be interrupted in the middle causing a ++ to be lost\n counter++;\n ...\n \/\/ thread T3\n \/\/ 3 operations: get, increment, store\n \/\/ this thread might be interrupted in the middle causing a ++ to be lost\n counter++;\n ...\n \/\/ later on, even if T2 and T3 have completed, you may see the counter as 1 or 2\n System.out.println(\"counter = \" + counter);\n<\/code><\/pre>\n<p>So locking is an issue even regardless of whether your threads are running on multiple or a single processor system.  See here for a <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/en.wikipedia.org\/wiki\/Atomicity_%28programming%29#Example_atomic_operation\">better example of non-atomic operations<\/a>.<\/p>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\"><\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved Java uses how many processors available in OS? [closed] <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] If any OS is multi-processor, then JVM uses all of them or one of them? On most modern hardware architectures, the JVM will make use of all CPUs\/cores made available to it by the OS. And As processors ahve different memory context so their corresponding memory threads will also have different memory contexts, so &#8230; <a title=\"[Solved] Java uses how many processors available in OS? [closed]\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-java-uses-how-many-processors-available-in-os-closed\/\" aria-label=\"More on [Solved] Java uses how many processors available in OS? [closed]\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[929,323],"class_list":["post-31840","post","type-post","status-publish","format-standard","hentry","category-solved","tag-concurrency","tag-java"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] Java uses how many processors available in OS? [closed] - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-java-uses-how-many-processors-available-in-os-closed\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] Java uses how many processors available in OS? [closed] - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] If any OS is multi-processor, then JVM uses all of them or one of them? On most modern hardware architectures, the JVM will make use of all CPUs\/cores made available to it by the OS. And As processors ahve different memory context so their corresponding memory threads will also have different memory contexts, so ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-java-uses-how-many-processors-available-in-os-closed\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2023-01-24T20:07:03+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-java-uses-how-many-processors-available-in-os-closed\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-java-uses-how-many-processors-available-in-os-closed\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] Java uses how many processors available in OS? [closed]\",\"datePublished\":\"2023-01-24T20:07:03+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-java-uses-how-many-processors-available-in-os-closed\/\"},\"wordCount\":439,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"keywords\":[\"concurrency\",\"java\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-java-uses-how-many-processors-available-in-os-closed\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-java-uses-how-many-processors-available-in-os-closed\/\",\"name\":\"[Solved] Java uses how many processors available in OS? [closed] - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"datePublished\":\"2023-01-24T20:07:03+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-java-uses-how-many-processors-available-in-os-closed\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-java-uses-how-many-processors-available-in-os-closed\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-java-uses-how-many-processors-available-in-os-closed\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] Java uses how many processors available in OS? [closed]\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jassweb.com\/solved\/#website\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jassweb.com\/solved\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"contentUrl\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] Java uses how many processors available in OS? [closed] - JassWeb","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:\/\/jassweb.com\/solved\/solved-java-uses-how-many-processors-available-in-os-closed\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] Java uses how many processors available in OS? [closed] - JassWeb","og_description":"[ad_1] If any OS is multi-processor, then JVM uses all of them or one of them? On most modern hardware architectures, the JVM will make use of all CPUs\/cores made available to it by the OS. And As processors ahve different memory context so their corresponding memory threads will also have different memory contexts, so ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-java-uses-how-many-processors-available-in-os-closed\/","og_site_name":"JassWeb","article_published_time":"2023-01-24T20:07:03+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-java-uses-how-many-processors-available-in-os-closed\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-java-uses-how-many-processors-available-in-os-closed\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] Java uses how many processors available in OS? [closed]","datePublished":"2023-01-24T20:07:03+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-java-uses-how-many-processors-available-in-os-closed\/"},"wordCount":439,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["concurrency","java"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-java-uses-how-many-processors-available-in-os-closed\/","url":"https:\/\/jassweb.com\/solved\/solved-java-uses-how-many-processors-available-in-os-closed\/","name":"[Solved] Java uses how many processors available in OS? [closed] - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2023-01-24T20:07:03+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-java-uses-how-many-processors-available-in-os-closed\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-java-uses-how-many-processors-available-in-os-closed\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-java-uses-how-many-processors-available-in-os-closed\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] Java uses how many processors available in OS? [closed]"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/31840","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=31840"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/31840\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=31840"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=31840"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=31840"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}