{"action":"created","comment":{"url":"https://api.github.com/repos/codurance/site/pulls/comments/75816373","id":75816373,"diff_hunk":"@@ -0,0 +1,111 @@\n+---\n+layout: post\n+asset-type: post\n+name: the-java-synchronisers\n+title: 'The Java Syncrhonisers' \n+date: 2016-08-22 10:00:00 +00:00\n+author: Carlos Morera de la Chica\n+image:\n+    src: /assets/img/custom/blog/synchronisation.jpg\n+tags:\n+- java\n+- threading\n+- synchronization\n+\n+canonical:\n+    name: my personal blog\n+    href: https://carlosmchica.github.io/the-java-synchronisers/\n+\n+---\n+\n+Threads communication happens primarily by sharing access to fields and objects. Although extremely efficient, this form of communication can lead to errors such as [thread interference](https://docs.oracle.com/javase/tutorial/essential/concurrency/interfere.html) and [memory consistency](https://docs.oracle.com/javase/tutorial/essential/concurrency/memconsist.html). Synchronization is a tool that helps to prevent these errors.\n+\n+However, synchronization does not come for free and can introduce waitings to access a lock or object that is currently being held by another thread. The waiting thread cannot use that object until the other thread releases the object. This condition is known as thread contention.\n+\n+In this post we will explore the different options that Java provides to deal with threads synchronization.\n+\n+## Synchronization essentials\n+\n+Java provides a series of mechanisms to handle basic thread synchronization and coordination. It supports fine-grained object access synchronization through [synchronized methods](#sync-methods) and [synchronized statements](#sync-statements). Basic thread coordination can be accomplished through [guarded blocks](#guarded-blocks). All mentioned mechanisms are built around acquiring and releasing objects' intrinsic lock.\n+\n+### Intrisic Lock\n+\n+Every Java object has associated an intrinsic lock. A thread that needs exclusive access to an object's fields has to acquire the object's lock before accessing them, releasing the intrinsic lock once it is done. Other threads trying to access the object will block until the thread holding the lock releases it.","path":"_posts/2016-08-22-the-java-synchronisers.md","position":33,"original_position":33,"commit_id":"5c11fce7d3863e3dcee2e0a789dd0c672743d36c","original_commit_id":"5c11fce7d3863e3dcee2e0a789dd0c672743d36c","user":{"login":"neomatrix369","id":1570917,"avatar_url":"https://avatars.githubusercontent.com/u/1570917?v=3","gravatar_id":"","url":"https://api.github.com/users/neomatrix369","html_url":"https://github.com/neomatrix369","followers_url":"https://api.github.com/users/neomatrix369/followers","following_url":"https://api.github.com/users/neomatrix369/following{/other_user}","gists_url":"https://api.github.com/users/neomatrix369/gists{/gist_id}","starred_url":"https://api.github.com/users/neomatrix369/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neomatrix369/subscriptions","organizations_url":"https://api.github.com/users/neomatrix369/orgs","repos_url":"https://api.github.com/users/neomatrix369/repos","events_url":"https://api.github.com/users/neomatrix369/events{/privacy}","received_events_url":"https://api.github.com/users/neomatrix369/received_events","type":"User","site_admin":false},"body":"accessing them, releasing ==> accessing them, and then releasing\r\n\r\n(otherwise the flow is not clear, and the important detail about releasing the lock isn't clear to the reader)","created_at":"2016-08-23T07:48:28Z","updated_at":"2016-08-23T07:48:28Z","html_url":"https://github.com/codurance/site/pull/313#discussion_r75816373","pull_request_url":"https://api.github.com/repos/codurance/site/pulls/313","_links":{"self":{"href":"https://api.github.com/repos/codurance/site/pulls/comments/75816373"},"html":{"href":"https://github.com/codurance/site/pull/313#discussion_r75816373"},"pull_request":{"href":"https://api.github.com/repos/codurance/site/pulls/313"}}},"pull_request":{"url":"https://api.github.com/repos/codurance/site/pulls/313","id":82179017,"html_url":"https://github.com/codurance/site/pull/313","diff_url":"https://github.com/codurance/site/pull/313.diff","patch_url":"https://github.com/codurance/site/pull/313.patch","issue_url":"https://api.github.com/repos/codurance/site/issues/313","number":313,"state":"open","locked":false,"title":"Add 'The Java synchronisers' blog post","user":{"login":"CarlosMChica","id":3494156,"avatar_url":"https://avatars.githubusercontent.com/u/3494156?v=3","gravatar_id":"","url":"https://api.github.com/users/CarlosMChica","html_url":"https://github.com/CarlosMChica","followers_url":"https://api.github.com/users/CarlosMChica/followers","following_url":"https://api.github.com/users/CarlosMChica/following{/other_user}","gists_url":"https://api.github.com/users/CarlosMChica/gists{/gist_id}","starred_url":"https://api.github.com/users/CarlosMChica/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CarlosMChica/subscriptions","organizations_url":"https://api.github.com/users/CarlosMChica/orgs","repos_url":"https://api.github.com/users/CarlosMChica/repos","events_url":"https://api.github.com/users/CarlosMChica/events{/privacy}","received_events_url":"https://api.github.com/users/CarlosMChica/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-08-22T12:02:20Z","updated_at":"2016-08-23T07:48:28Z","closed_at":null,"merged_at":null,"merge_commit_sha":"393d370fe63c05a12a80f8efc2c0c89951854ee4","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/codurance/site/pulls/313/commits","review_comments_url":"https://api.github.com/repos/codurance/site/pulls/313/comments","review_comment_url":"https://api.github.com/repos/codurance/site/pulls/comments{/number}","comments_url":"https://api.github.com/repos/codurance/site/issues/313/comments","statuses_url":"https://api.github.com/repos/codurance/site/statuses/5c11fce7d3863e3dcee2e0a789dd0c672743d36c","head":{"label":"codurance:java_syncrhonizers","ref":"java_syncrhonizers","sha":"5c11fce7d3863e3dcee2e0a789dd0c672743d36c","user":{"login":"codurance","id":5751452,"avatar_url":"https://avatars.githubusercontent.com/u/5751452?v=3","gravatar_id":"","url":"https://api.github.com/users/codurance","html_url":"https://github.com/codurance","followers_url":"https://api.github.com/users/codurance/followers","following_url":"https://api.github.com/users/codurance/following{/other_user}","gists_url":"https://api.github.com/users/codurance/gists{/gist_id}","starred_url":"https://api.github.com/users/codurance/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codurance/subscriptions","organizations_url":"https://api.github.com/users/codurance/orgs","repos_url":"https://api.github.com/users/codurance/repos","events_url":"https://api.github.com/users/codurance/events{/privacy}","received_events_url":"https://api.github.com/users/codurance/received_events","type":"Organization","site_admin":false},"repo":{"id":38424930,"name":"site","full_name":"codurance/site","owner":{"login":"codurance","id":5751452,"avatar_url":"https://avatars.githubusercontent.com/u/5751452?v=3","gravatar_id":"","url":"https://api.github.com/users/codurance","html_url":"https://github.com/codurance","followers_url":"https://api.github.com/users/codurance/followers","following_url":"https://api.github.com/users/codurance/following{/other_user}","gists_url":"https://api.github.com/users/codurance/gists{/gist_id}","starred_url":"https://api.github.com/users/codurance/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codurance/subscriptions","organizations_url":"https://api.github.com/users/codurance/orgs","repos_url":"https://api.github.com/users/codurance/repos","events_url":"https://api.github.com/users/codurance/events{/privacy}","received_events_url":"https://api.github.com/users/codurance/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/codurance/site","description":"","fork":false,"url":"https://api.github.com/repos/codurance/site","forks_url":"https://api.github.com/repos/codurance/site/forks","keys_url":"https://api.github.com/repos/codurance/site/keys{/key_id}","collaborators_url":"https://api.github.com/repos/codurance/site/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/codurance/site/teams","hooks_url":"https://api.github.com/repos/codurance/site/hooks","issue_events_url":"https://api.github.com/repos/codurance/site/issues/events{/number}","events_url":"https://api.github.com/repos/codurance/site/events","assignees_url":"https://api.github.com/repos/codurance/site/assignees{/user}","branches_url":"https://api.github.com/repos/codurance/site/branches{/branch}","tags_url":"https://api.github.com/repos/codurance/site/tags","blobs_url":"https://api.github.com/repos/codurance/site/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/codurance/site/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/codurance/site/git/refs{/sha}","trees_url":"https://api.github.com/repos/codurance/site/git/trees{/sha}","statuses_url":"https://api.github.com/repos/codurance/site/statuses/{sha}","languages_url":"https://api.github.com/repos/codurance/site/languages","stargazers_url":"https://api.github.com/repos/codurance/site/stargazers","contributors_url":"https://api.github.com/repos/codurance/site/contributors","subscribers_url":"https://api.github.com/repos/codurance/site/subscribers","subscription_url":"https://api.github.com/repos/codurance/site/subscription","commits_url":"https://api.github.com/repos/codurance/site/commits{/sha}","git_commits_url":"https://api.github.com/repos/codurance/site/git/commits{/sha}","comments_url":"https://api.github.com/repos/codurance/site/comments{/number}","issue_comment_url":"https://api.github.com/repos/codurance/site/issues/comments{/number}","contents_url":"https://api.github.com/repos/codurance/site/contents/{+path}","compare_url":"https://api.github.com/repos/codurance/site/compare/{base}...{head}","merges_url":"https://api.github.com/repos/codurance/site/merges","archive_url":"https://api.github.com/repos/codurance/site/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/codurance/site/downloads","issues_url":"https://api.github.com/repos/codurance/site/issues{/number}","pulls_url":"https://api.github.com/repos/codurance/site/pulls{/number}","milestones_url":"https://api.github.com/repos/codurance/site/milestones{/number}","notifications_url":"https://api.github.com/repos/codurance/site/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/codurance/site/labels{/name}","releases_url":"https://api.github.com/repos/codurance/site/releases{/id}","deployments_url":"https://api.github.com/repos/codurance/site/deployments","created_at":"2015-07-02T09:54:02Z","updated_at":"2016-03-14T09:39:20Z","pushed_at":"2016-08-23T07:45:49Z","git_url":"git://github.com/codurance/site.git","ssh_url":"git@github.com:codurance/site.git","clone_url":"https://github.com/codurance/site.git","svn_url":"https://github.com/codurance/site","homepage":null,"size":224031,"stargazers_count":1,"watchers_count":1,"language":"CSS","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":7,"mirror_url":null,"open_issues_count":6,"forks":7,"open_issues":6,"watchers":1,"default_branch":"master"}},"base":{"label":"codurance:master","ref":"master","sha":"47fb3fbe8691ac5917851b562da01128c9b84d10","user":{"login":"codurance","id":5751452,"avatar_url":"https://avatars.githubusercontent.com/u/5751452?v=3","gravatar_id":"","url":"https://api.github.com/users/codurance","html_url":"https://github.com/codurance","followers_url":"https://api.github.com/users/codurance/followers","following_url":"https://api.github.com/users/codurance/following{/other_user}","gists_url":"https://api.github.com/users/codurance/gists{/gist_id}","starred_url":"https://api.github.com/users/codurance/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codurance/subscriptions","organizations_url":"https://api.github.com/users/codurance/orgs","repos_url":"https://api.github.com/users/codurance/repos","events_url":"https://api.github.com/users/codurance/events{/privacy}","received_events_url":"https://api.github.com/users/codurance/received_events","type":"Organization","site_admin":false},"repo":{"id":38424930,"name":"site","full_name":"codurance/site","owner":{"login":"codurance","id":5751452,"avatar_url":"https://avatars.githubusercontent.com/u/5751452?v=3","gravatar_id":"","url":"https://api.github.com/users/codurance","html_url":"https://github.com/codurance","followers_url":"https://api.github.com/users/codurance/followers","following_url":"https://api.github.com/users/codurance/following{/other_user}","gists_url":"https://api.github.com/users/codurance/gists{/gist_id}","starred_url":"https://api.github.com/users/codurance/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codurance/subscriptions","organizations_url":"https://api.github.com/users/codurance/orgs","repos_url":"https://api.github.com/users/codurance/repos","events_url":"https://api.github.com/users/codurance/events{/privacy}","received_events_url":"https://api.github.com/users/codurance/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/codurance/site","description":"","fork":false,"url":"https://api.github.com/repos/codurance/site","forks_url":"https://api.github.com/repos/codurance/site/forks","keys_url":"https://api.github.com/repos/codurance/site/keys{/key_id}","collaborators_url":"https://api.github.com/repos/codurance/site/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/codurance/site/teams","hooks_url":"https://api.github.com/repos/codurance/site/hooks","issue_events_url":"https://api.github.com/repos/codurance/site/issues/events{/number}","events_url":"https://api.github.com/repos/codurance/site/events","assignees_url":"https://api.github.com/repos/codurance/site/assignees{/user}","branches_url":"https://api.github.com/repos/codurance/site/branches{/branch}","tags_url":"https://api.github.com/repos/codurance/site/tags","blobs_url":"https://api.github.com/repos/codurance/site/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/codurance/site/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/codurance/site/git/refs{/sha}","trees_url":"https://api.github.com/repos/codurance/site/git/trees{/sha}","statuses_url":"https://api.github.com/repos/codurance/site/statuses/{sha}","languages_url":"https://api.github.com/repos/codurance/site/languages","stargazers_url":"https://api.github.com/repos/codurance/site/stargazers","contributors_url":"https://api.github.com/repos/codurance/site/contributors","subscribers_url":"https://api.github.com/repos/codurance/site/subscribers","subscription_url":"https://api.github.com/repos/codurance/site/subscription","commits_url":"https://api.github.com/repos/codurance/site/commits{/sha}","git_commits_url":"https://api.github.com/repos/codurance/site/git/commits{/sha}","comments_url":"https://api.github.com/repos/codurance/site/comments{/number}","issue_comment_url":"https://api.github.com/repos/codurance/site/issues/comments{/number}","contents_url":"https://api.github.com/repos/codurance/site/contents/{+path}","compare_url":"https://api.github.com/repos/codurance/site/compare/{base}...{head}","merges_url":"https://api.github.com/repos/codurance/site/merges","archive_url":"https://api.github.com/repos/codurance/site/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/codurance/site/downloads","issues_url":"https://api.github.com/repos/codurance/site/issues{/number}","pulls_url":"https://api.github.com/repos/codurance/site/pulls{/number}","milestones_url":"https://api.github.com/repos/codurance/site/milestones{/number}","notifications_url":"https://api.github.com/repos/codurance/site/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/codurance/site/labels{/name}","releases_url":"https://api.github.com/repos/codurance/site/releases{/id}","deployments_url":"https://api.github.com/repos/codurance/site/deployments","created_at":"2015-07-02T09:54:02Z","updated_at":"2016-03-14T09:39:20Z","pushed_at":"2016-08-23T07:45:49Z","git_url":"git://github.com/codurance/site.git","ssh_url":"git@github.com:codurance/site.git","clone_url":"https://github.com/codurance/site.git","svn_url":"https://github.com/codurance/site","homepage":null,"size":224031,"stargazers_count":1,"watchers_count":1,"language":"CSS","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":7,"mirror_url":null,"open_issues_count":6,"forks":7,"open_issues":6,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/codurance/site/pulls/313"},"html":{"href":"https://github.com/codurance/site/pull/313"},"issue":{"href":"https://api.github.com/repos/codurance/site/issues/313"},"comments":{"href":"https://api.github.com/repos/codurance/site/issues/313/comments"},"review_comments":{"href":"https://api.github.com/repos/codurance/site/pulls/313/comments"},"review_comment":{"href":"https://api.github.com/repos/codurance/site/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/codurance/site/pulls/313/commits"},"statuses":{"href":"https://api.github.com/repos/codurance/site/statuses/5c11fce7d3863e3dcee2e0a789dd0c672743d36c"}}}}
{"actor":{"display_login":"neomatrix369"}}