2- Thread Pools
Jul 03, 2026 22:55
· 1:46
· English
· Whisper Turbo
· 2 דוברים
תעתיק זה פג היום.
שדרוג לאחסון קבוע →
מציג בלבד
0:03
S…
Speaker 1 (2- Thread Pools)
Threads are the fundamental building blocks of concurrent applications,
0:07
S…
Speaker 1 (2- Thread Pools)
but working directly with threads has a couple of problems.
0:10
S…
Speaker 1 (2- Thread Pools)
The first problem is that we have a limited number of threads available to us.
0:13
S…
Speaker 1 (2- Thread Pools)
So if you're not careful,
0:15
S…
Speaker 1 (2- Thread Pools)
you may end up creating too many threads and get out of memory exceptions.
0:19
S…
Speaker 1 (2- Thread Pools)
So our application will crash.
0:21
S…
Speaker 1 (2- Thread Pools)
The other issue is that creating and destroying threads is costly.
0:24
S…
Speaker 1 (2- Thread Pools)
If you have a thousand tasks to execute,
0:26
S…
Speaker 1 (2- Thread Pools)
like a thousand images to download and only 10 threads available,
0:30
S…
Speaker 1 (2- Thread Pools)
we have to download 10 images using this thread.
0:32
S…
Speaker 1 (2- Thread Pools)
Then once these threads are complete,
0:34
S…
Speaker 1 (2- Thread Pools)
you have to create another set of 10 threads and we have to repeat this
0:38
S…
Speaker 1 (2- Thread Pools)
several times to execute all our tasks.
0:41
S…
Speaker 1 (2- Thread Pools)
creating and destroying threads is expensive.
0:43
S…
Speaker 1 (2- Thread Pools)
So Java 5 came up with a solution called a thread pool.
0:47
S…
Speaker 1 (2- Thread Pools)
A thread pool is essentially a pool of threads called worker threads,
0:51
S…
Speaker 1 (2- Thread Pools)
and this thread can be reused to execute several tasks.
0:55
S…
Speaker 1 (2- Thread Pools)
When a worker thread finishes,
0:56
S…
Speaker 1 (2- Thread Pools)
it's returned back to the pool,
0:58
S…
Speaker 1 (2- Thread Pools)
so it can be reused to execute another task.
1:01
S…
Speaker 1 (2- Thread Pools)
So these threads are not destroyed and recreated.
1:04
S…
Speaker 1 (2- Thread Pools)
They're always available and are reused to execute many tasks.
1:07
S…
Speaker 1 (2- Thread Pools)
Also,
1:09
S…
Speaker 1 (2- Thread Pools)
Because the thread pool has a fixed number of threads,
1:11
S…
Speaker 1 (2- Thread Pools)
we don't have to worry about creating too many threads and running out of memory.
1:14
S…
Speaker 2 (2- Thread Pools)
For example,
1:15
S…
Speaker 1 (2- Thread Pools)
we can create a thread pool with 10 threads and submit a thousand tasks
1:19
S…
Speaker 1 (2- Thread Pools)
to it.
1:20
S…
Speaker 1 (2- Thread Pools)
The thread pool would take care of assigning our tasks to the threads.
1:23
S…
Speaker 1 (2- Thread Pools)
If all threads are busy,
1:25
S…
Speaker 1 (2- Thread Pools)
the new tasks will wait in a queue.
1:27
S…
Speaker 1 (2- Thread Pools)
As soon as a thread becomes available,
1:29
S…
Speaker 1 (2- Thread Pools)
it will pick up a task from the queue and execute it.
1:32
S…
Speaker 1 (2- Thread Pools)
So with this model,
1:33
S…
Speaker 1 (2- Thread Pools)
we don't have to think about creating threads directly.
1:36
S…
Speaker 2 (2- Thread Pools)
Instead,
1:37
S…
Speaker 1 (2- Thread Pools)
we submit our tasks to a thread pool and let the thread pool take care
1:41
S…
Speaker 1 (2- Thread Pools)
of thread manipulation.
1:42
S…
Speaker 1 (2- Thread Pools)
I'll show you how to do that next.
תעתיק זה נוצר על ידי AI (הכרה אוטומטית של דיבור). ייתכן שיש בו שגיאות אשר מאשרות את השמע המקורי לשימוש קריטי. מדיניות AI
תקציר
לחץ לסכם כדי ליצור סיכום AI של תעתיק זה.
מסכם...
שאל את אל על התעתיק הזה.
שאל כל דבר על התמליל הזה, הבינה המלאכותית תמצא חלקים רלוונטיים ותענה.