์‰๋„์ž‰ ์—ฐ์Šต: ๐Ÿ”ฅ Java Multithreading Rapid Fire | Can You Answer These Interview Questions? #shorts - ์˜์ƒ์œผ๋กœ ์˜์–ด ๋งํ•˜๊ธฐ ๋ฐฐ์šฐ๊ธฐ

๋ ˆ์Šจ ๋งŒ๋“œ๋Š” ์ค‘...
1
What is multi -threading?
2
Multi -threading means performing multiple tasks in parallel.
3
This is done using threads.
4
Thread is basically a small unit that performs some tasks inside your application.
5
Suppose you want to perform three tasks in parallel, you can create three threads and each thread can perform one task.
6
How do you create a thread in Java?
7
There are mainly two ways.
8
Either extend a class named Thread or implement an interface named Runnable.
9
Explain the first approach.
10
We extend the thread class and override its run method.
11
Whatever task we want the thread to perform, we write inside run.
12
Then we create an object of our task class.
13
Using this object we call the start method.
14
What is the difference between start and run?
15
Start creates a new thread and then internally executes run.
16
Calling run directly does not create a new thread.
17
Explain the second approach.
18
We implement the runnable interface and override its run method.
19
Runnable only has run, it does not have start.
20
So we can't call start directly using the task object.
21
Hence we create a thread object and pass the task object to its constructor.
22
This thread object then calls start.
23
What was the need for this approach?
24
Its needed because Java does not support multiple inheritance.
25
Suppose our task class already extends another class then it won't be able to extend thread
26
but it can still implement runnable that is allowed.

์‹ค์ƒํ™œ์—์„œ์˜ ์‹œ๋‚˜๋ฆฌ์˜ค

์ด ๋น„๋””์˜ค๋Š” Java ๋ฉ€ํ‹ฐ์Šค๋ ˆ๋”ฉ์— ๊ด€ํ•œ ์ธํ„ฐ๋ทฐ ์งˆ๋ฌธ๊ณผ ๋‹ต๋ณ€์„ ๋‹ค๋ฃจ๊ณ  ์žˆ๋Š”๋ฐ, ์‹ค์ œ๋กœ ๊ธฐ์ˆ  ๋ฉด์ ‘์—์„œ ์ž์ฃผ ๋งˆ์ฃผ์น˜๋Š” ์ƒํ™ฉ์„ ์žฌํ˜„ํ•œ ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์ธํ„ฐ๋ทฐ์–ด์™€ ์ธํ„ฐ๋ทฐ์ด ๊ฐ„์˜ ๋น ๋ฅธ ์†๋„์˜ ๋Œ€ํ™”๋Š” ์˜์–ด๋กœ ๊ธฐ์ˆ  ์šฉ์–ด๋ฅผ ์ •ํ™•ํ•˜๊ฒŒ ์ „๋‹ฌํ•˜๊ณ , ๋…ผ๋ฆฌ์ ์œผ๋กœ ์„ค๋ช…ํ•˜๋Š” ๋Šฅ๋ ฅ์„ ์š”๊ตฌํ•ฉ๋‹ˆ๋‹ค. ํŠนํžˆ IELTS ์Šคํ”ผํ‚น ์‹œํ—˜์—์„œ๋„ ์ด์™€ ์œ ์‚ฌํ•˜๊ฒŒ ๋ณต์žกํ•œ ์ฃผ์ œ๋ฅผ ๋ช…ํ™•ํžˆ ํ‘œํ˜„ํ•ด์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ๋งŽ์œผ๋ฏ€๋กœ, ์ด ๋Œ€ํ™”๋ฅผ ํ†ตํ•ด ๊ธฐ์ˆ  ์˜์–ด๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ์ผ๋ฐ˜์ ์ธ ๋…ผ์ˆ  ๋Šฅ๋ ฅ๋„ ๊ธฐ๋ฅผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์™ธ์›Œ๋‘๋ฉด ์œ ์šฉํ•œ ๊ตฌ๋ฌธ๊ณผ ์—ฐ์–ด

  • perform multiple tasks in parallel: "๋ณ‘๋ ฌ๋กœ ์—ฌ๋Ÿฌ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•˜๋‹ค" โ€“ ๊ธฐ์ˆ  ๋ถ„์•ผ์—์„œ ์ž์ฃผ ์‚ฌ์šฉ๋˜๋Š” ํ‘œํ˜„์œผ๋กœ, ๋ฉ€ํ‹ฐํƒœ์Šคํ‚น์„ ์„ค๋ช…ํ•  ๋•Œ ํ•„์ˆ˜์ ์ž…๋‹ˆ๋‹ค.
  • override its run method: "run ๋ฉ”์„œ๋“œ๋ฅผ ์˜ค๋ฒ„๋ผ์ด๋“œํ•˜๋‹ค" โ€“ ๊ฐ์ฒด์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ์—์„œ ๋ฉ”์„œ๋“œ ์žฌ์ •์˜๋ฅผ ์„ค๋ช…ํ•˜๋Š” ํ‘œํ˜„์œผ๋กœ, ์ •ํ™•ํ•œ ์šฉ์–ด ์‚ฌ์šฉ์ด ์ค‘์š”ํ•ฉ๋‹ˆ๋‹ค.
  • create a new thread: "์ƒˆ๋กœ์šด ์Šค๋ ˆ๋“œ๋ฅผ ์ƒ์„ฑํ•˜๋‹ค" โ€“ ๋ฉ€ํ‹ฐ์Šค๋ ˆ๋”ฉ์˜ ๊ธฐ๋ณธ ๊ฐœ๋…์„ ์ „๋‹ฌํ•˜๋Š” ํ•ต์‹ฌ ๊ตฌ๋ฌธ์ž…๋‹ˆ๋‹ค.
  • pass the task object to its constructor: "์ž‘์—… ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑ์ž์— ์ „๋‹ฌํ•˜๋‹ค" โ€“ ํด๋ž˜์Šค์™€ ์ธํ„ฐํŽ˜์ด์Šค์˜ ๊ด€๊ณ„๋ฅผ ์„ค๋ช…ํ•  ๋•Œ ์ž์ฃผ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.
  • does not support multiple inheritance: "๋‹ค์ค‘ ์ƒ์†์„ ์ง€์›ํ•˜์ง€ ์•Š๋‹ค" โ€“ Java์˜ ํŠน์ง•์„ ์„ค๋ช…ํ•˜๋Š” ์ค‘์š”ํ•œ ๋ฌธ์žฅ์ž…๋‹ˆ๋‹ค.

๋‹น์‹ ์˜ ์‰๋„์ž‰ ์ฑŒ๋ฆฐ์ง€

์‰๋„์ž‰(shadow speak)์ด๋ž€ ์›๋ณธ ์Œ์„ฑ์„ ๋”ฐ๋ผ ๋งํ•˜๋ฉด์„œ ๋ฐœ์Œ, ์–ต์–‘, ์†๋„๋ฅผ ๋™์‹œ์— ์—ฐ์Šตํ•˜๋Š” ๋ฐฉ๋ฒ•์œผ๋กœ, ์˜์–ด ๋ฐœ์Œ ๊ต์ •๊ณผ ๋งํ•˜๊ธฐ ๋Šฅ๋ ฅ์„ ๋น ๋ฅด๊ฒŒ ํ–ฅ์ƒ์‹œํ‚ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด ๋น„๋””์˜ค์˜ ๋Œ€ํ™”๋ฅผ ์‚ฌ์šฉํ•ด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ณผ์ •์„ ์‹œ๋„ํ•ด ๋ณด์„ธ์š”: 1. ๋น„๋””์˜ค๋ฅผ 0.75๋ฐฐ ์†๋„๋กœ ์žฌ์ƒํ•˜๋ฉด์„œ ์ •ํ™•ํ•˜๊ฒŒ ๋ฐœ์Œ์„ ๋”ฐ๋ผํ•ฉ๋‹ˆ๋‹ค. 2. ๊ฐ ๊ตฌ๋ฌธ์˜ ๊ฐ•์„ธ๊ฐ€ ์žˆ๋Š” ๋‹จ์–ด๋ฅผ ํŒŒ์•…ํ•˜๊ณ , ์›๋ณธ๊ณผ ๊ฐ™์€ ๊ฐ•๋„๋กœ ๋ฐœ์Œํ•ฉ๋‹ˆ๋‹ค. 3. 1.0๋ฐฐ ์†๋„๋กœ ์˜ฌ๋ ค๊ฐ€๋ฉด์„œ๋„ ํ๋ฆ„์„ ๋Š์ง€ ์•Š๊ณ  ๋”ฐ๋ผ๊ฐ€๋„๋ก ์—ฐ์Šตํ•ฉ๋‹ˆ๋‹ค. ์ด ๊ณผ์ •์„ ํ•˜๋ฃจ์— 5๋ถ„์”ฉ 1์ฃผ์ผ ๋ฐ˜๋ณตํ•˜๋ฉด, shadowspeaks ๊ธฐ์ˆ ์ด ๋ˆˆ์— ๋„๊ฒŒ ํ–ฅ์ƒ๋  ๊ฒƒ์ž…๋‹ˆ๋‹ค. ํŠนํžˆ IELTS ์Šคํ”ผํ‚น์—์„œ ์š”๊ตฌ๋˜๋Š” ์œ ์ฐฝ์„ฑ๊ณผ ์ •ํ™•์„ฑ์„ ๋™์‹œ์— ๊ธฐ๋ฅผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์‰๋„์ž‰์ด๋ž€? ์˜์–ด ์‹ค๋ ฅ์„ ๋น ๋ฅด๊ฒŒ ํ‚ค์šฐ๋Š” ๊ณผํ•™์  ๋ฐฉ๋ฒ•

์‰๋„์ž‰(Shadowing)์€ ์›๋ž˜ ์ „๋ฌธ ํ†ต์—ญ์‚ฌ ํ›ˆ๋ จ์„ ์œ„ํ•ด ๊ฐœ๋ฐœ๋œ ์–ธ์–ด ํ•™์Šต ๊ธฐ๋ฒ•์œผ๋กœ, ๋‹ค์–ธ์–ด ํ•™์ž์ธ Dr. Alexander Arguelles์— ์˜ํ•ด ๋Œ€์ค‘ํ™”๋œ ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค. ํ•ต์‹ฌ ์›๋ฆฌ๋Š” ๊ฐ„๋‹จํ•˜์ง€๋งŒ ๋งค์šฐ ๊ฐ•๋ ฅํ•ฉ๋‹ˆ๋‹ค: ์›์–ด๋ฏผ์˜ ์˜์–ด๋ฅผ ๋“ค์œผ๋ฉด์„œ 1~2์ดˆ์˜ ์งง์€ ์ง€์—ฐ์œผ๋กœ ์ฆ‰์‹œ ์†Œ๋ฆฌ ๋‚ด์–ด ๋”ฐ๋ผ ๋งํ•˜๋Š” ๊ฒƒโ€”โ€”๋งˆ์น˜ '๊ทธ๋ฆผ์ž(shadow)'์ฒ˜๋Ÿผ ํ™”์ž๋ฅผ ๋”ฐ๋ผ๊ฐ€๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. ๋ฌธ๋ฒ• ๊ณต๋ถ€๋‚˜ ์ˆ˜๋™์ ์ธ ์ฒญ์ทจ์™€ ๋‹ฌ๋ฆฌ, ์‰๋„์ž‰์€ ๋‡Œ์™€ ์ž… ๊ทผ์œก์ด ๋™์‹œ์— ์‹ค์‹œ๊ฐ„์œผ๋กœ ์˜์–ด๋ฅผ ์ฒ˜๋ฆฌํ•˜๊ณ  ์žฌํ˜„ํ•˜๋„๋ก ํ›ˆ๋ จํ•ฉ๋‹ˆ๋‹ค. ์—ฐ๊ตฌ์— ๋”ฐ๋ฅด๋ฉด ์ด ๋ฐฉ๋ฒ•์€ ๋ฐœ์Œ ์ •ํ™•๋„, ์–ต์–‘, ๋ฆฌ๋“ฌ, ์—ฐ์Œ, ์ฒญ์ทจ๋ ฅ, ๋งํ•˜๊ธฐ ์œ ์ฐฝ์„ฑ์„ ํฌ๊ฒŒ ํ–ฅ์ƒ์‹œํ‚ต๋‹ˆ๋‹ค. IELTS ์Šคํ”ผํ‚น ์ค€๋น„์™€ ์ž์—ฐ์Šค๋Ÿฌ์šด ์˜์–ด ์†Œํ†ต์„ ์›ํ•˜๋Š” ๋ถ„๋“ค์—๊ฒŒ ํŠนํžˆ ํšจ๊ณผ์ ์ž…๋‹ˆ๋‹ค.

์„€๋„์ž‰ ๋ฐฉ๋ฒ•: ๋‹จ๊ณ„๋ณ„ ์ „์ฒด ๊ฐ€์ด๋“œ ์ฝ๊ธฐ โ†’