From e1769ddb4185970c78192c9c36d9d15f47140806 Mon Sep 17 00:00:00 2001 From: Marlon <7106775+smlc@users.noreply.github.com> Date: Wed, 7 Aug 2024 08:49:41 +0100 Subject: [PATCH 1/2] intro --- content/post/java-concurrency-lock.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 content/post/java-concurrency-lock.md diff --git a/content/post/java-concurrency-lock.md b/content/post/java-concurrency-lock.md new file mode 100644 index 0000000..8bbd6c2 --- /dev/null +++ b/content/post/java-concurrency-lock.md @@ -0,0 +1,21 @@ +--- +title: "Java Synchronized vs ReentrantLock locking" +date: "2024-08-04" +author: "Marlon" +--- + +In this article we will explore the basic building block to do synchronization know as `intrinsic locking` and the high level synchronization +offer by the `java.util.concurrent` package. + +Please anwser the following question : +- What is the purpose of lock ? +- What does it means to be reentrant ? +- Describe the different way to coordinate communication between two threads and their impact on the thread lifecycle using low level synchronization constructs. + - synchronize : Where can we use it and what can be synchronize ? + - Wait/Notify + - Notify vs NotifyAll : When would you use notify and notifyAll + - Interrupt : What happened if we interrupt a running thread or a thread not yet start ? + - What the impact of calling join on the deamons thread ? + - Does yield guarante other thread will be executed ? +## Instrinsic locks + From 06fb597434f37b66904f85c0a0e2a9b38a127cbb Mon Sep 17 00:00:00 2001 From: Marlon <7106775+smlc@users.noreply.github.com> Date: Mon, 19 Aug 2024 08:41:51 +0100 Subject: [PATCH 2/2] Update java-concurrency-lock.md --- content/post/java-concurrency-lock.md | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/content/post/java-concurrency-lock.md b/content/post/java-concurrency-lock.md index 8bbd6c2..de169f5 100644 --- a/content/post/java-concurrency-lock.md +++ b/content/post/java-concurrency-lock.md @@ -9,13 +9,26 @@ offer by the `java.util.concurrent` package. Please anwser the following question : - What is the purpose of lock ? +- Each instance class object have 'monitor lock, entry set and wait set' assigned to them. Describe the impact of each one, and describe when each one is modified - What does it means to be reentrant ? - Describe the different way to coordinate communication between two threads and their impact on the thread lifecycle using low level synchronization constructs. - synchronize : Where can we use it and what can be synchronize ? - Wait/Notify - Notify vs NotifyAll : When would you use notify and notifyAll - Interrupt : What happened if we interrupt a running thread or a thread not yet start ? - - What the impact of calling join on the deamons thread ? - - Does yield guarante other thread will be executed ? + - What is the impact of calling join on the daemon thread? + - Does yield guarantee other threads will be executed? + ## Instrinsic locks +First what is intrinsic locks, it's the most basic building block the Java language provide to synchronize thread. + +### What is the purpose of lock ? + +- If you need only one thread to access an resource (mutex), synchronize is what you need. +- If you need an condition to be true for an exclusive access to an resource (monitor) + + +Ressources : +- https://docs.oracle.com/javase/tutorial/essential/concurrency/locksync.html +- https://www.infoworld.com/article/2168239/how-the-java-virtual-machine-performs-thread-synchronization.html