๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๊ฐœ๋ฐœ์ƒํ™œ/Java

์‹คํ–‰ ์ง€์—ฐ TimeUnit.Sleep

by cocococo331 2023. 5. 31.

๋”œ๋ ˆ์ด๋ฅผ ์ค„ ๋•Œ, Thread.Sleep ๋ณด๋‹ค๋Š” TimeUnit.Sleep๋ฅผ ์“ฐ์ž.

์ฝ”๋“œ๋ฅผ ๋ณด๋ฉด ๊ฒฐ๊ตญ TimeUnit.Sleep์—์„œ Thread.sleep๋ฅผ ์ฝœํ•œ๋‹ค.


๊ธฐ๊ฐ€ ๊ธฐ์ง€๋งŒ TimeUnit.Sleep๋ฅผ ์“ฐ๋Š” ์ด์œ ๋Š”

 

1. ๊ฐ€๋…์„ฑ์ด ๋” ์ข‹๋‹ค
๋งŒ์•ฝ์— 3๋ถ„ Delay๋ฅผ ์ค€๋‹ค
Thread.Sleep(3 * 60 * 1000); == Thread.sleep(180000); //์œผํœด ํ•œ๋ฒˆ์— ๋ชป ์•Œ์•„ ๋จน์–ด
=
TimeUnit.MINUTES.Sleep(3);

 

2. 1์˜ ์—ฐ์žฅ์„ ์œผ๋กœ ์‹œ๊ฐ„ ๋‹จ์œ„ ์„ ํƒ์ด ๊ฐ€๋Šฅํ•˜๋‹ค.
TimeUnit: DAYS, HOURS, MICROSECONDS, MILLISECONDS, MINUTES, NANOSECONDS.SECONDS


3. ์•ˆ์ •์„ฑ
์‹œ๊ฐ„ ์ดˆ๊ณผ๊ฐ€ ์–‘์ˆ˜์ธ์ง€ ํ™•์ธํ•œ ํ›„ ํ˜ธ์ถœํ•จ. (ํƒ€์ž„ ์•„์›ƒ์ด ์Œ์ˆ˜์ด๋ฉด Thread.sleep์ด ๋ฐœ์ƒ ์•Š๊ณ  IllegalArgumentException)

 

๊ฒฐ๋ก  ์ž„์˜ ์‹คํ–‰ ์ง€์—ฐ์ด ํ•„์š”ํ•œ ๊ฒฝ์šฐ TimeUnit.sleep์„ ์‚ฌ์šฉ

'๊ฐœ๋ฐœ์ƒํ™œ > Java' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

๋กฌ๋ณต ๋นŒ๋” ๊ธฐ๋ณธ๊ฐ’  (0) 2024.06.11
char to int  (0) 2023.05.10
ObjectMapper ์‚ฌ์šฉ List Mapping  (0) 2022.11.28
[Java] List ๋‚˜๋ˆ„๊ธฐ  (0) 2022.05.23
[Java] Null String Casting  (0) 2022.04.29