{"id":1388,"date":"2022-07-07T11:30:27","date_gmt":"2023-08-18T01:20:09","guid":{"rendered":"https:\/\/www.silicloud.com\/blog\/uncategorized\/ensuring-java-code-is-thread-safe\/"},"modified":"2024-03-03T14:15:00","modified_gmt":"2024-03-03T14:15:00","slug":"java-thread-ensuring-safety","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/blog\/java-thread-ensuring-safety\/","title":{"rendered":"Java thread ensuring Java code is thread-safe"},"content":{"rendered":"<p>The topic of Thread Safety in Java holds great significance. Java offers support for a multi-threaded environment through Java Threads. It is crucial to note that when multiple threads are created from the same Object, they share its object variables. This can result in data inconsistency when the threads are utilized for both reading and updating the shared data.<\/p>\n<h2>Ensuring multiple <a href=\"https:\/\/www.w3schools.com\/java\/java_threads.asp\">threads<\/a> can access without conflicts<\/h2>\n<p>Data inconsistency occurs due to the fact that updating a field value is not an indivisible process. It involves three steps: reading the current value, performing the necessary operations to obtain the updated value, and assigning the updated value to the field reference. To illustrate this, we can observe a simple program in which multiple threads are updating the shared data.<\/p>\n<pre class=\"post-pre\"><code>package com.scdev.threads;\r\n\r\npublic class ThreadSafety {\r\n\r\n    public static void main(String[] args) throws InterruptedException {\r\n    \r\n        ProcessingThread pt = new ProcessingThread();\r\n        Thread t1 = new Thread(pt, \"t1\");\r\n        t1.start();\r\n        Thread t2 = new Thread(pt, \"t2\");\r\n        t2.start();\r\n        \/\/wait for threads to finish processing\r\n        t1.join();\r\n        t2.join();\r\n        System.out.println(\"Processing count=\"+pt.getCount());\r\n    }\r\n\r\n}\r\n\r\nclass ProcessingThread implements Runnable{\r\n    private int count;\r\n    \r\n    @Override\r\n    public void run() {\r\n        for(int i=1; i &lt; 5; i++){\r\n            processSomething(i);\r\n        \tcount++;\r\n        }\r\n    }\r\n\r\n    public int getCount() {\r\n        return this.count;\r\n    }\r\n\r\n    private void processSomething(int i) {\r\n        \/\/ processing some job\r\n        try {\r\n            Thread.sleep(i*1000);\r\n        } catch (InterruptedException e) {\r\n            e.printStackTrace();\r\n        }\r\n    }\r\n    \r\n}\r\n<\/code><\/pre>\n<p>In the program mentioned above, the value of the variable &#8220;count&#8221; is incremented by 1 four times in a loop. As there are two threads running simultaneously, the expected value of &#8220;count&#8221; after both threads finish executing should be 8. However, when running the program multiple times, it is observed that the value of &#8220;count&#8221; fluctuates between 6, 7, and 8. This inconsistency is due to the fact that even though the operation &#8220;count++&#8221; appears to be atomic, it is not, resulting in data corruption.<\/p>\n<h2>Ensuring thread safety in Java.<\/h2>\n<p>In Java, ensuring thread safety is the procedure of making our program secure for use in a multithreaded environment. There are various approaches available to achieve thread safety in our program.<\/p>\n<ul class=\"post-ul\">\n<li>Synchronization is the easiest and most widely used tool for thread safety in java.<\/li>\n<li>Use of Atomic Wrapper classes from java.util.concurrent.atomic package. For example AtomicInteger<\/li>\n<li>Use of locks from java.util.concurrent.locks package.<\/li>\n<li>Using thread safe collection classes, check this post for usage of ConcurrentHashMap for thread safety.<\/li>\n<li>Using volatile keyword with variables to make every thread read the data from memory, not read from thread cache.<\/li>\n<\/ul>\n<h3>Synchronized keyword in Java<\/h3>\n<p>Using synchronization allows us to attain thread-safety, as the JVM ensures that synchronized code is executed by only one thread at any given moment. The synchronized keyword in Java is employed to generate synchronized code, and it utilizes locks on Objects or Classes to guarantee that only a single thread executes the synchronized code.<\/p>\n<ul class=\"post-ul\">\n<li>Java synchronization works on locking and unlocking of the resource before any thread enters into synchronized code, it has to acquire the lock on the Object and when code execution ends, it unlocks the resource that can be locked by other threads. In the meantime, other threads are in wait state to lock the synchronized resource.<\/li>\n<li>We can use synchronized keyword in two ways, one is to make a complete method synchronized and another way is to create synchronized block.<\/li>\n<li>When a method is synchronized, it locks the Object, if method is static it locks the Class, so it\u2019s always best practice to use synchronized block to lock the only sections of method that needs synchronization.<\/li>\n<li>While creating a synchronized block, we need to provide the resource on which lock will be acquired, it can be XYZ.class or any Object field of the class.<\/li>\n<li>synchronized(this) will lock the Object before entering into the synchronized block.<\/li>\n<li>You should use the lowest level of locking, for example, if there are multiple synchronized block in a class and one of them is locking the Object, then other synchronized blocks will also be not available for execution by other threads. When we lock an Object, it acquires a lock on all the fields of the Object.<\/li>\n<li>Java Synchronization provides data integrity on the cost of performance, so it should be used only when it\u2019s absolutely necessary.<\/li>\n<li>Java Synchronization works only in the same JVM, so if you need to lock some resource in multiple JVM environment, it will not work and you might have to look after some global locking mechanism.<\/li>\n<li>Java Synchronization could result in deadlocks, check this post about deadlock in java and how to avoid them.<\/li>\n<li>Java synchronized keyword cannot be used for constructors and variables.<\/li>\n<li>It is preferable to create a dummy private Object to use for the synchronized block so that it\u2019s reference can\u2019t be changed by any other code. For example, if you have a setter method for Object on which you are synchronizing, it\u2019s reference can be changed by some other code leads to the parallel execution of the synchronized block.<\/li>\n<li>We should not use any object that is maintained in a constant pool, for example String should not be used for synchronization because if any other code is also locking on same String, it will try to acquire lock on the same reference object from String pool and even though both the codes are unrelated, they will lock each other.<\/li>\n<\/ul>\n<p>To ensure thread safety, we must implement the below code modifications in the aforementioned program.<\/p>\n<pre class=\"post-pre\"><code>    \/\/dummy object variable for synchronization\r\n    private Object mutex=new Object();\r\n    ...\r\n    \/\/using synchronized block to read, increment and update count value synchronously\r\n    synchronized (mutex) {\r\n            count++;\r\n    }\r\n<\/code><\/pre>\n<p>Let&#8217;s examine some instances of synchronization and the lessons we can derive from them.<\/p>\n<pre class=\"post-pre\"><code>public class MyObject {\r\n \r\n  \/\/ Locks on the object's monitor\r\n  public synchronized void doSomething() { \r\n    \/\/ ...\r\n  }\r\n}\r\n \r\n\/\/ Hackers code\r\nMyObject myObject = new MyObject();\r\nsynchronized (myObject) {\r\n  while (true) {\r\n    \/\/ Indefinitely delay myObject\r\n    Thread.sleep(Integer.MAX_VALUE); \r\n  }\r\n}\r\n<\/code><\/pre>\n<p>Take note that the code used by hackers attempts to grab the lock on the myObject instance and does not release it. As a result, the doSomething() method becomes stuck waiting for the lock, leading to a deadlock and ultimately causing a Denial of Service (DoS) to the system.<\/p>\n<pre class=\"post-pre\"><code>public class MyObject {\r\n  public Object lock = new Object();\r\n \r\n  public void doSomething() {\r\n    synchronized (lock) {\r\n      \/\/ ...\r\n    }\r\n  }\r\n}\r\n\r\n\/\/untrusted code\r\n\r\nMyObject myObject = new MyObject();\r\n\/\/change the lock Object reference\r\nmyObject.lock = new Object();\r\n<\/code><\/pre>\n<p>Please observe that the lock Object can be accessed publicly, enabling the execution of synchronized blocks concurrently in multiple threads by modifying its reference. The same situation applies if you possess a private Object but possess a setter method to alter its reference.<\/p>\n<pre class=\"post-pre\"><code>public class MyObject {\r\n  \/\/locks on the class object's monitor\r\n  public static synchronized void doSomething() { \r\n    \/\/ ...\r\n  }\r\n}\r\n \r\n\/\/ hackers code\r\nsynchronized (MyObject.class) {\r\n  while (true) {\r\n    Thread.sleep(Integer.MAX_VALUE); \/\/ Indefinitely delay MyObject\r\n  }\r\n}\r\n<\/code><\/pre>\n<p>Be aware that the hacker&#8217;s code has gained control over the class monitor and is not letting go of it. This will lead to a deadlock situation and result in a Denial of Service (DoS) within the system. Here&#8217;s another instance where several threads are simultaneously operating on the same set of String arrays, and after processing, they add their thread names to the respective array values.<\/p>\n<pre class=\"post-pre\"><code>package com.scdev.threads;\r\n\r\nimport java.util.Arrays;\r\n\r\npublic class SyncronizedMethod {\r\n\r\n    public static void main(String[] args) throws InterruptedException {\r\n        String[] arr = {\"1\",\"2\",\"3\",\"4\",\"5\",\"6\"};\r\n        HashMapProcessor hmp = new HashMapProcessor(arr);\r\n        Thread t1=new Thread(hmp, \"t1\");\r\n        Thread t2=new Thread(hmp, \"t2\");\r\n        Thread t3=new Thread(hmp, \"t3\");\r\n        long start = System.currentTimeMillis();\r\n        \/\/start all the threads\r\n        t1.start();t2.start();t3.start();\r\n        \/\/wait for threads to finish\r\n        t1.join();t2.join();t3.join();\r\n        System.out.println(\"Time taken= \"+(System.currentTimeMillis()-start));\r\n        \/\/check the shared variable value now\r\n        System.out.println(Arrays.asList(hmp.getMap()));\r\n    }\r\n\r\n}\r\n\r\nclass HashMapProcessor implements Runnable{\r\n    \r\n    private String[] strArr = null;\r\n    \r\n    public HashMapProcessor(String[] m){\r\n        this.strArr=m;\r\n    }\r\n    \r\n    public String[] getMap() {\r\n        return strArr;\r\n    }\r\n\r\n    @Override\r\n    public void run() {\r\n        processArr(Thread.currentThread().getName());\r\n    }\r\n\r\n    private void processArr(String name) {\r\n        for(int i=0; i &lt; strArr.length; i++){\r\n            \/\/process data and append thread name\r\n            processSomething(i);\r\n            addThreadName(i, name);\r\n        }\r\n    }\r\n    \r\n    private void addThreadName(int i, String name) {\r\n        strArr[i] = strArr[i] +\":\"+name;\r\n    }\r\n\r\n    private void processSomething(int index) {\r\n        \/\/ processing some job\r\n        try {\r\n            Thread.sleep(index*1000);\r\n        } catch (InterruptedException e) {\r\n            e.printStackTrace();\r\n        }\r\n    }\r\n    \r\n}\r\n<\/code><\/pre>\n<p>This is the result I get when I execute the program mentioned above.<\/p>\n<pre class=\"post-pre\"><code>Time taken= 15005\r\n[1:t2:t3, 2:t1, 3:t3, 4:t1:t3, 5:t2:t1, 6:t3]\r\n<\/code><\/pre>\n<p>The corruption of the String array values occurs due to shared data and lack of synchronization. To ensure thread safety in our program, we can modify the addThreadName() method as follows.<\/p>\n<pre class=\"post-pre\"><code>    private Object lock = new Object();\r\n    private void addThreadName(int i, String name) {\r\n        synchronized(lock){\r\n        strArr[i] = strArr[i] +\":\"+name;\r\n        }\r\n    }\r\n<\/code><\/pre>\n<p>Following this modification, our program is functioning properly and the program is now producing the accurate result.<\/p>\n<pre class=\"post-pre\"><code>Time taken= 15004\r\n[1:t1:t2:t3, 2:t2:t1:t3, 3:t2:t3:t1, 4:t3:t2:t1, 5:t2:t1:t3, 6:t2:t1:t3]\r\n<\/code><\/pre>\n<p>I hope you have gained knowledge about thread safety in Java, including thread-safe programming and the utilization of the synchronized keyword. That concludes our discussion.<\/p>\n<p>&nbsp;<\/p>\n<p>More Java tutors<\/p>\n<p><a class=\"LinkSuggestion__Link-sc-1gewdgc-4 cLBplk\" href=\"https:\/\/www.silicloud.com\/blog\/addition-assignment-operator-in-java\/\" target=\"_blank\" rel=\"noopener\">Addition Assignment Operator mean in Java<span class=\"sc-gswNZR eASTkv\">(Opens in a new browser tab)<\/span><\/a><\/p>\n<p><a class=\"LinkSuggestion__Link-sc-1gewdgc-4 cLBplk\" href=\"https:\/\/www.silicloud.com\/blog\/spring-mvc-handlerinterceptoradapter-and-handlerinterceptor\/\" target=\"_blank\" rel=\"noopener\">Spring MVC HandlerInterceptorAdapter and HandlerInterceptor.<span class=\"sc-gswNZR eASTkv\">(Opens in a new browser tab)<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The topic of Thread Safety in Java holds great significance. Java offers support for a multi-threaded environment through Java Threads. It is crucial to note that when multiple threads are created from the same Object, they share its object variables. This can result in data inconsistency when the threads are utilized for both reading and [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-1388","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Java thread ensuring Java code is thread-safe - Blog - Silicon Cloud<\/title>\n<meta name=\"description\" content=\"Java thread offers support for a multi-threaded environment through Java Threads.Ensuring multiple threads can access without conflicts\" \/>\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.silicloud.com\/blog\/java-thread-ensuring-safety\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java thread ensuring Java code is thread-safe\" \/>\n<meta property=\"og:description\" content=\"Java thread offers support for a multi-threaded environment through Java Threads.Ensuring multiple threads can access without conflicts\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/blog\/java-thread-ensuring-safety\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/SiliCloudGlobal\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-08-18T01:20:09+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-03T14:15:00+00:00\" \/>\n<meta name=\"author\" content=\"Sophia Anderson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@SiliCloudGlobal\" \/>\n<meta name=\"twitter:site\" content=\"@SiliCloudGlobal\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sophia Anderson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/java-thread-ensuring-safety\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/java-thread-ensuring-safety\/\"},\"author\":{\"name\":\"Sophia Anderson\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/19a24313de9c988db3d69226b4a40a30\"},\"headline\":\"Java thread ensuring Java code is thread-safe\",\"datePublished\":\"2023-08-18T01:20:09+00:00\",\"dateModified\":\"2024-03-03T14:15:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/java-thread-ensuring-safety\/\"},\"wordCount\":1105,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\"},\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/java-thread-ensuring-safety\/\",\"url\":\"https:\/\/www.silicloud.com\/blog\/java-thread-ensuring-safety\/\",\"name\":\"Java thread ensuring Java code is thread-safe - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#website\"},\"datePublished\":\"2023-08-18T01:20:09+00:00\",\"dateModified\":\"2024-03-03T14:15:00+00:00\",\"description\":\"Java thread offers support for a multi-threaded environment through Java Threads.Ensuring multiple threads can access without conflicts\",\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/java-thread-ensuring-safety\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/blog\/java-thread-ensuring-safety\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/java-thread-ensuring-safety\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.silicloud.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java thread ensuring Java code is thread-safe\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/blog\/\",\"name\":\"Silicon Cloud Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\",\"name\":\"Silicon Cloud Blog\",\"url\":\"https:\/\/www.silicloud.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png\",\"contentUrl\":\"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png\",\"width\":1024,\"height\":1024,\"caption\":\"Silicon Cloud Blog\"},\"image\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/SiliCloudGlobal\/\",\"https:\/\/twitter.com\/SiliCloudGlobal\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/19a24313de9c988db3d69226b4a40a30\",\"name\":\"Sophia Anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/c726c09aa40e37115fb5c62d0c3ed62c16ca255d3763e2e3ae83a70ddf8c2175?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/c726c09aa40e37115fb5c62d0c3ed62c16ca255d3763e2e3ae83a70ddf8c2175?s=96&d=mm&r=g\",\"caption\":\"Sophia Anderson\"},\"url\":\"https:\/\/www.silicloud.com\/blog\/author\/sophiaanderson\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Java thread ensuring Java code is thread-safe - Blog - Silicon Cloud","description":"Java thread offers support for a multi-threaded environment through Java Threads.Ensuring multiple threads can access without conflicts","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.silicloud.com\/blog\/java-thread-ensuring-safety\/","og_locale":"en_US","og_type":"article","og_title":"Java thread ensuring Java code is thread-safe","og_description":"Java thread offers support for a multi-threaded environment through Java Threads.Ensuring multiple threads can access without conflicts","og_url":"https:\/\/www.silicloud.com\/blog\/java-thread-ensuring-safety\/","og_site_name":"Blog - Silicon Cloud","article_publisher":"https:\/\/www.facebook.com\/SiliCloudGlobal\/","article_published_time":"2023-08-18T01:20:09+00:00","article_modified_time":"2024-03-03T14:15:00+00:00","author":"Sophia Anderson","twitter_card":"summary_large_image","twitter_creator":"@SiliCloudGlobal","twitter_site":"@SiliCloudGlobal","twitter_misc":{"Written by":"Sophia Anderson","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.silicloud.com\/blog\/java-thread-ensuring-safety\/#article","isPartOf":{"@id":"https:\/\/www.silicloud.com\/blog\/java-thread-ensuring-safety\/"},"author":{"name":"Sophia Anderson","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/19a24313de9c988db3d69226b4a40a30"},"headline":"Java thread ensuring Java code is thread-safe","datePublished":"2023-08-18T01:20:09+00:00","dateModified":"2024-03-03T14:15:00+00:00","mainEntityOfPage":{"@id":"https:\/\/www.silicloud.com\/blog\/java-thread-ensuring-safety\/"},"wordCount":1105,"commentCount":0,"publisher":{"@id":"https:\/\/www.silicloud.com\/blog\/#organization"},"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/blog\/java-thread-ensuring-safety\/","url":"https:\/\/www.silicloud.com\/blog\/java-thread-ensuring-safety\/","name":"Java thread ensuring Java code is thread-safe - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/blog\/#website"},"datePublished":"2023-08-18T01:20:09+00:00","dateModified":"2024-03-03T14:15:00+00:00","description":"Java thread offers support for a multi-threaded environment through Java Threads.Ensuring multiple threads can access without conflicts","breadcrumb":{"@id":"https:\/\/www.silicloud.com\/blog\/java-thread-ensuring-safety\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/blog\/java-thread-ensuring-safety\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/blog\/java-thread-ensuring-safety\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.silicloud.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Java thread ensuring Java code is thread-safe"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/blog\/#website","url":"https:\/\/www.silicloud.com\/blog\/","name":"Silicon Cloud Blog","description":"","publisher":{"@id":"https:\/\/www.silicloud.com\/blog\/#organization"},"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.silicloud.com\/blog\/#organization","name":"Silicon Cloud Blog","url":"https:\/\/www.silicloud.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png","contentUrl":"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png","width":1024,"height":1024,"caption":"Silicon Cloud Blog"},"image":{"@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/SiliCloudGlobal\/","https:\/\/twitter.com\/SiliCloudGlobal"]},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/19a24313de9c988db3d69226b4a40a30","name":"Sophia Anderson","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/c726c09aa40e37115fb5c62d0c3ed62c16ca255d3763e2e3ae83a70ddf8c2175?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c726c09aa40e37115fb5c62d0c3ed62c16ca255d3763e2e3ae83a70ddf8c2175?s=96&d=mm&r=g","caption":"Sophia Anderson"},"url":"https:\/\/www.silicloud.com\/blog\/author\/sophiaanderson\/"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/1388","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/comments?post=1388"}],"version-history":[{"count":2,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/1388\/revisions"}],"predecessor-version":[{"id":1642,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/1388\/revisions\/1642"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/media?parent=1388"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/categories?post=1388"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/tags?post=1388"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}