Java์ ๋์์ฑ ๊ด๋ จ ๋ถ๋ถ์ ์ดํผ๋ค๊ฐ 'happens-before relationship'์ด๋ ์ฉ์ด๊ฐ ์์ฃผ ๋ฑ์ฅํ๋ ๊ฒ์ ์์๋ค.
https://www.logicbig.com/tutorials/core-java-tutorial/java-multi-threading/happens-before.html
https://en.wikipedia.org/wiki/Happened-before
https://preshing.com/20130702/the-happens-before-relation/
https://jenkov.com/tutorials/java-concurrency/java-happens-before-guarantee.html
https://javarevisited.blogspot.com/2020/01/what-is-happens-before-in-java-concurrency.html
https://www.geeksforgeeks.org/happens-before-relationship-in-java/
์ํคํผ๋์์ ์ค๋ช . happens-before๊ฐ ์๋๋ผ happened-before๋ก ์ฉ์ด ์ค๋ช ์ ํ๊ณ ์๊ธฐ๋ ํ์ง๋ง, ๋์ ์๋ฏธ๊ฐ ๋์ผํ ๊ฒ ๊ฐ๋ค.
In computer science, the happened-before relation (denoted: →) is a relation between the result of two events, such that if one event should happen before another event, the result must reflect that, even if those events are in reality executed out of order (usually to optimize program flow).
๋ฐ๋ฒ์ญ
์ปดํจํฐ ๊ณผํ์์, happened-before ๊ด๊ณ๋ ๋ ์ด๋ฒคํธ์ ๊ฒฐ๊ณผ๋ค ์ฌ์ด์ ๊ด๊ณ์ด๋ค. ๋ง์ฝ ํ ์ด๋ฒคํธ๊ฐ ๋ค๋ฅธ ์ด๋ฒคํธ ์ ์ ์ผ์ด๋์ผ ํ๋ค๋ฉด, ๊ฒฐ๊ณผ๋ ๋ฐ๋์ ๊ทธ๊ฒ์ ๋ฐ์ํด์ผ ํ๋ค. ์ค์ ๋ก ๊ทธ ์ด๋ฒคํธ๋ค์ด (์ผ๋ฐ์ ์ผ๋ก ํ๋ก๊ทธ๋จ์ ํ๋ฆ์ ์ต์ ํํ๊ธฐ ์ํด) ์์๋๋ก ์คํ๋์ง ์๋๋ผ๋ ๋ง์ด๋ค.
๋ด๊ฐ ์ดํดํ ๋ฐ๋ ์ด๋ ๋ค.
์ด๋ฒคํธ a์ ๊ฒฐ๊ณผ๋ฅผ ๊ฐ์ง๊ณ ์ด๋ฒคํธ b์ ๊ฒฐ๊ณผ๋ฅผ ๋ด์ผ ํ ๊ฒฝ์ฐ > a happenes-before b.
์ฐ๋ ๋ 1์์ ์ด๋ฒคํธ a, ์ฐ๋ ๋ 2์์ ์ด๋ฒคํธ b๋ฅผ ๋์์ ์คํํ๋ฉด, ์คํ ์์๊ฐ a ๋ค์ b์ผ์ง, b ๋ค์ a ์ผ์ง๋ ๋ชจ๋ฅด์ง๋ง, ๊ฒฐ๊ณผ๋ a์ ๊ฒฐ๊ณผ๋ฅผ ๊ฐ์ง๊ณ b์ ๊ฒฐ๊ณผ๋ฅผ ๋ด์ผ ํ๋ค.
Happens-before ์ฉ์ด๋ Java๋ง์ ์ฉ์ด๋ ์๋๋ค. happenes-before relation์ ํตํด ๋ฉํฐ ์ฐ๋ ๋, ๋ฉํฐ ์ฝ์ด ํ๊ฒฝ์์์ ์ฑ๋ฅ์ ํฅ์(๋ฉํฐ์ฐ๋ ๋-๋์์ฑ, ๋ฉํฐ ์ฝ์ด-๋ณ๋ ฌ์ฑ)์ํค๋ฉด์ ์ ํํ ๊ฒฐ๊ณผ ๊ฐ์ด ๋์ค๋๋ก ๋ณด์ฅํ๋ ๊ฒ์ด๋ค.
Java์์ Happens-before relationship์ ๊ตฌํํ๋ ๋ฐฉ๋ฒ
- Synchronized ์ฌ์ฉ
- Volatile ์ฌ์ฉ
'๋น ๊ตฌ๋ฉ ์ฑ์ฐ๊ธฐ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Android][Glide] You can't start or clear loads in RequestListener or Target callbacks. (0) | 2023.03.08 |
---|---|
[Android] ์์คํ ๋ฐ ์ ์ด (0) | 2023.03.03 |
[Kotlin] Obejct๋ก ์ ์ธํ Singleton ๊ฐ์ฒด์ ์์ฑ์ Lazy ํ๊ฐ? (1) | 2023.03.03 |
[Network] HTTP headers (0) | 2023.03.02 |
[Android][Java][์ํธํ] MessageDigest (0) | 2023.02.28 |