Java Multithreading Tutorial for Beginners #7: How to safely stop a thread ?

preview_player
Показать описание

It is really important that we properly close a thread, especially if the thread does work on things that can lead to data loss, data inconsistency etc. In this chapter, we will look into a method where we make use of a flag to properly stop a thread if needed.

You can find the source code of this chapter in the following GitHub repository.

Website:-

#Multithreading
#GenuineCoder
#Java
Рекомендации по теме
Комментарии
Автор

Sir, How to interrupt Scanner it is not getting interrupt or stopping using your solution as well.

varunmanchanda
Автор

You weren't so accurate when you said join(int) would kill a thread if it doesn't finish in given time. Actually join() does not kill it. System.exit(0) just kills JVM so your thread would end prematurely.
You can try if if you remove System.exit(). It would just print result after main thread as it took more time to finish :)

stefanjankovic
Автор

Oh man the background music makes me think my iPhone alarm keeps going off.

DanceManAlex
welcome to shbcf.ru