Java Threads - Creating, starting and stopping threads in Java

preview_player
Показать описание
A Java Thread is like a virtual CPU that can execute part of your Java application in parallel with the application main Java thread. This Java Thread tutorial explains how to create, start, pause, stop and join threads in Java.

Chapters
0:00 Java Threads Introduction
0:24 Create and start a Java Thread
0:50 The four ways to specify what code a Java Thread should execute
1:49 Create a subclass of the Java Thread class
2:47 Create a class that implements the Runnable interface
3:37 Implement the Runnable interface with an anonymous class
4:21 Implement the Runnable interface with a Java Lambda Expression
5:29 Obtain reference to currently executing Thread
5:56 Get and set Thread name
6:33 Start multiple threads
8:09 Stop a Java Thread
11:33 Mark a Java Thread as a Daemon thread
13:23 Join a thread - wait for the Java Thread to terminate
15:01 OS level threads and user space level threads

Java Threads tutorial - textual version:

Java Concurrency and Multithreading - video playlist:

Java Lambda Expressions tutorial - text / video playlist
Рекомендации по теме
Комментарии
Автор

9:00
Stopping threads
Synchronized keyword will stop threads executing the method concurrently but if a new 2nd object is created, then two different threads can call the method concurrently on each of the object instances. So synchronized only works if multiple threads call same object

8:30 the native way of stopping a thread will stop a thread in an unkown state. Implement a runnable that has a stop function instead of using the default stop method. The custom stop function sets a stop requested variable, then the runnable run method can keep checking if a stop has been requested or not and terminate on its own terms (saving any state before stopping).

12:00 the main thread can terminate, but as long as any of the threads it started are still running, then the JVM will stay running. Daemon threads will NOT keep the jvm alive if they are the last thread running, so if you want the jvm to stop running after all other threads have terminated thread.setDaemon(true)

14:10 can make main thread wait for another thread by using thread.join

15:15 OS threads vs more lightweight threads project loom (fibers)

mostinho
Автор

This playlist is a jackpot for learning concurrency in Java, thanks for creating these

SouthernSeneca
Автор

hey Jakob. I usually give a visit to your webiste at work on a weekly basis. just wanted to say thanks for the effort. It has helped me a lot at work

luckyluke
Автор

Loved it, threads have always been hard to grasp but you made it way easier

destro
Автор

I just don't have words to express all my gratitude for all your work

enable
Автор

Another awesome video, thanks Jakob!👏

JonasKeil
Автор

God of Concurency..i have bene flowing you since my 2014 when you used to write blog post only...by going through your post i attend interview like a LION when they ask mutithreading qns....Thanks a Lot form 10+ yrs exp guy from BLR, India.

shubhamagarwal
Автор

Thank you for this amazing tutorial that explains a lot of important concepts related to Threading in Java. Much appreciated.

waqasahmed
Автор

I have to thank you for the fantastic work you do here. This video (along with the related article) both summarized and was more informative than the last three lectures on multithreading in my comp-sci course. People like you make learning easy, and are a real gift to the world.

mortbringsli
Автор

THANK YOU so much. This solved a "freezing" issue when I was trying to use media in my JSwing. So helpful!

GeoffClark
Автор

I appreciate your tutorials. They are really helpful as I had no clue during the lecture haha. Also, your videos are very well organized and concise unlike many other videos. Thank you!

BillPark-eyih
Автор

The clarity, conciseness and simplicity of your videos and articles are a immense contribution for tech!! Thank you so much for your effort!!

MarceloAX
Автор

Thanks for your effort. I also like watching your textual tutorials. As a fresh Java Programmer, I acquired more new knowledge from your tutorial. Thanks a lot!

hailiu
Автор

thanks, this series is much better then reading the boring "java concurrency" book
short and to the point examples you can follow along, 10/10

SoeaOu
Автор

I am linking this Youtube page to my class in a discussion about Violent Deaths and threads and not using the variable for Java thread. This is a great example of some of the information we are covering. Great Job on explaining.

jefferycroom
Автор

Jakob, I am Latino and I have to tell you that you are the best and most detailed in explaining. I am super grateful to be able to learn from your videos and website. Graciass!!

juandebenedetti
Автор

Exceptional tutorial. Very clearly explained & well-organized examples!

gregorytippett
Автор

Good to have a revision on this concept. Thanks for you effort.

_graymatter__
Автор

Hello Jakob.. Loved this simple and straight to the point tutorial. Thank you for making this!

WiseFatOwl
Автор

Lots of love from the bottom of my heart <3.
You have put a lot effort for the tuts. Thanks for the understanding the struggle of a normal student .

journeytothedream
visit shbcf.ru