Advanced Java: Multi-threading Part 12 - Semaphores

preview_player
Показать описание
-------------------------------------------------------------------------------------------------------------------------------------------
How to use Semaphores in multi-threaded Java code. Semaphores allow you to control how many threads can access a resource simultaneously; you can also use them as locks if the mood takes you, with the advantage that you can release (unlock) them from threads other than where you locked them.
--------------------------------------------------------------------------------------------------------------------------------------------
Рекомендации по теме
Комментарии
Автор

Countless online tutorials and failed attempts at reading tedious documentation later I finally understand multithreading. Absolute gem. Thanks a lot.

neoforu
Автор

Reviewing for an Operating Systems exam and came across this video during my studies. Extremely well done, it was a delight to watch. Liked and subscribed :)

zam
Автор

Finally, a video which provides an up-to-date use of semaphores in concurrency that I can understand. Thank you so much.

neux
Автор

It's Beethoven, Piano Concert 4, played by Debbie Hu. Actually no, I find music distracting. These days I don't really do much programming apart from the occasional burst, but sometimes I used to listen to trance. It's an acquired taste ... most trance is tacky and vile, but some is really quite delicious. Many of my colleagues felt they could program really well while listening to Internet radio.

caveofprogramming
Автор

Cheers, that sounds like a good idea. I'll keep it in mind when I get round to re-doing this one. This one is a bit unnecessarily complex, I see that now.

caveofprogramming
Автор

Hey, i'm new to multi-threading, but i thought your connection example with semaphores was perfect. Everything was very well presented. Fantastic job!
kesten

workless
Автор

I'm in the process of remaking these videos with a better mic, so if you have any suggestions, I'd like to hear them.

caveofprogramming
Автор

@DaSilentLprince Haha, yes I can see how it would be confusing, now you mention it! There's a Connection class; it has a connect() method, and it counts the number of things that are currently 'connected'. I should have called the class "Server" really.

caveofprogramming
Автор

Excellent explanation. If i didnt get it wrong, when you call sem.acquire() if the object "sem" doesnt have a permit available the code below that sentence will not execute till a permit is realease and that could happen in the same or another thread if the threads share the same semaphore object. Is that right?

JackMelon
Автор

I like your  Multi-threading Tutorials. but in this case you make its so much harder to understand with the static method...

ufo
Автор

love your start music, gets me into the video instantly

dorkendr
Автор

Well i like your tutorials, but when you are adding new stuff to program like Semaphore here, try to use it on something rly simple. You could explain how semaphore multy threading work on simple displaying of String vector. and limit how many of them u want to display with semaphore.

dosenmarko
Автор

Will the JSP and Swings will use these Multithreading techniques to a Wide Range?

xthmath
Автор

When to use Semaphore? I am unable to link this example with real time multithreading scanerio.

RaviKumar-cwvl
Автор

I'm a little confused here. Isn't semaphone acquire and release like synchronized. Why do we need synchronized(this) after acquireing a semaphore?

eilay
Автор

QUESTION: Can you invoke the semaphore upon regular threads? as in thread t1 = new Thread(new Runnable(){
public void run(){

}
}); ??

keithscull
Автор

Should the release be inside the catch block of the acquire? I.E. what happens if the exception is thrown on the acquire, and then a release is called?

grandmaatemysweater
Автор

Do you listen to any music while programming? From your intro, I would guess piano. Also what is the name of your intro piano song?

bautrey
Автор

So the point seems to be to put a thread.sleep() right OUTSIDE of the synchronized block, I see that. BUT, I don't understand WHY since we're calling the entire METHOD 200 times via the ExecutorService, why wouldn't that thread.sleep be executing within EVERY iteration of the loop constantly?

bluex
Автор

Is there any necessity of making the Connection class, Singleton ?

MrJonnis