No video

Java threads 🧵

  Рет қаралды 110,516

Bro Code

Bro Code

Күн бұрын

Пікірлер: 136
@BroCodez
@BroCodez 4 жыл бұрын
//********************************************************************* public class Main{ public static void main(String[] args) throws InterruptedException{ /* thread = A thread of execution in a program (kind of like a virtual CPU) The JVM allows an application to have multiple threads running concurrently Each thread can execute parts of you code in parallel with the main thread Each thread has a priority. Threads with higher priority are executed in preference compared to threads with a lower priority The Java Virtual Machine continues to execute threads until either of the following occurs 1. The exit method of class Runtime has been called 2. All user threads have died When a JVM starts up, there is a thread which calls the main method This thread is called “main” Daemon thread is a low priority thread that runs in background to perform tasks such as garbage collection JVM terminates itself when all user threads (non-daemon threads) finish their execution */ //System.out.println(Thread.activeCount()); //Thread.currentThread().setName("MAIN"); //System.out.println(Thread.currentThread().getName()); //Thread.currentThread().setPriority(10); //System.out.println(Thread.currentThread().getPriority()); //System.out.println(Thread.currentThread().isAlive()); /* for(int i =3;i>0;i--) { System.out.println(i); Thread.sleep(1000); } System.out.println("You are done!"); */ //MyThread thread2 = new MyThread(); //thread2.setDaemon(true); //System.out.println(thread2.isDaemon()); //thread2.start(); //System.out.println(thread2.isAlive()); //thread2.setName("2nd thread"); //System.out.println(thread2.getName()); //thread2.setPriority(1); //System.out.println(thread2.getPriority()); //System.out.println(Thread.activeCount()); } } //********************************************************************* public class MyThread extends Thread{ @Override public void run() { if(this.isDaemon()) { System.out.println("This is a daemon thread that is running"); } else { System.out.println("This is a user thread that is running"); } } } //*********************************************************************
@aquate9637
@aquate9637 4 жыл бұрын
You should create a website and post your code there, I think people would really appreciate it.
@nikolamarkovic9906
@nikolamarkovic9906 2 жыл бұрын
Ched
@spicynoodles3317
@spicynoodles3317 2 жыл бұрын
Bro Code, please know you're out here saving lives, tears, grades, and reputations. I'm in an internship doing java programming and you're about 95% of the reason I've only cried once.
@yusuphmwaigomole3104
@yusuphmwaigomole3104 2 жыл бұрын
Fantastic
@joyceasante8292
@joyceasante8292 Жыл бұрын
Practicing... public class Main { public static void main (String[]args) throws InterruptedException { //System.out.println(Thread.activeCount()); //Thread.currentThread().setName("Main"); //System.out.println(Thread.currentThread().getName()); //Thread.currentThread().setPriority(1); //System.out.println(Thread.currentThread().getPriority()); //System.out.println(Thread.currentThread().isAlive()); /*for (int i = 8; i > 0; i--) { System.out.println (i); Thread.sleep (2000); } System.out.println("Done!"); */ MyThread thread2 = new MyThread(); thread2.setDaemon(true); System.out.println(thread2.isDaemon()); thread2.start(); //System.out.println(thread2.isAlive()); //thread2.setName("Thread II"); //System.out.println(thread2.getName()); //thread2.setPriority(1); //System.out.println(thread2.getPriority()); System.out.println(Thread.activeCount()); } } ************ public class MyThread extends Thread{ @Override public void run(){ if(this.isDaemon()){ System.out.println("Daemon thread is confirmed."); } else{ System.out.println("User thread is running."); } } }
@matthewbrightman3398
@matthewbrightman3398 2 жыл бұрын
Hey man! Last summer I spent my vacation in Florida watching your channel; wrote a cool game. This summer I'm on assignment in Germany, and I'm back to watching your channel again. You have the perfect way of teaching Java! 10-15 minutes, examples, fun. Just great.
@chsktricks9397
@chsktricks9397 Жыл бұрын
Hey! Hi matthew
@scotch5094
@scotch5094 3 ай бұрын
which course did he teach about game bro
@SpeaksYourWord
@SpeaksYourWord 3 ай бұрын
@@scotch5094 He only has beginner courses unfortunately but it would be great if he made advanced ones even if paid.
@IdeeFixeGamer
@IdeeFixeGamer 3 жыл бұрын
pure gold, these tutorials are genius. more tutorials please
@nizarouertani1315
@nizarouertani1315 3 жыл бұрын
by far the best java youtube channel
@srujansanga2689
@srujansanga2689 10 ай бұрын
this teaching saved me one day of exercising on pdfs about threads
@argyriskappa2789
@argyriskappa2789 3 жыл бұрын
Bro, you just saved my semester. You da best.
@HIMANSHU-mt1jk
@HIMANSHU-mt1jk Жыл бұрын
Us bro
@saransridhara6622
@saransridhara6622 Жыл бұрын
Saved mine as well 💥💥
@joelcruz2873
@joelcruz2873 Жыл бұрын
This was very useful after spending a couple days learning the basics of threads. If I began everything with watching this video, I wouldn't have known what was going on
@affable.pebble
@affable.pebble Ай бұрын
Thank you! I appreciate all the explanations and examples!
@screenname96
@screenname96 Жыл бұрын
I love your channel, thank you so much. You make things so concise. I come to your channel for every topic in my Java class and view the videos on it before going through my professors provided resources. It helps me tremendously. Bless you, my guy.
@furkanveliisk4113
@furkanveliisk4113 Жыл бұрын
simple yet effective. thanks for the lectures brah
@envektro2519
@envektro2519 3 жыл бұрын
I hope you keep doing these kind of videos
@jenkar5716
@jenkar5716 Жыл бұрын
Virgin College: Takes hefty amout of fee but still doesn't know how to teach young minds Chad Bro: *Simple explanation and Free of cost*
@LostKitty64x
@LostKitty64x Жыл бұрын
This video is extremely helpful and not hard to watch at all so far. I need this information but got tired of seeing 3 hour long videos drag on. So far so good. thank you for providing this content to me. I need it for a mod I'm trying to build.
@mahdib9361
@mahdib9361 3 жыл бұрын
Amazing Video please Continue
@jusun2009
@jusun2009 5 ай бұрын
Very helpful content and thorough explanation. Thank you for sharing!👍
@nawfalnjm5699
@nawfalnjm5699 3 жыл бұрын
your playlists are amazing . thank you !
@adityavikramsingh802
@adityavikramsingh802 4 ай бұрын
This guy is an absolute DAWGGGGGGGGGGGGG
@ibrahimylmaz8378
@ibrahimylmaz8378 Жыл бұрын
thank you Bro :) I got my first job, I studied Java with your videos, super helpful.
@user-jp3le2lz6d
@user-jp3le2lz6d Жыл бұрын
Bro is genius in Java !
@110dhruvpatel5
@110dhruvpatel5 9 ай бұрын
you deserve a sub.
@girl6994
@girl6994 4 жыл бұрын
I used thread in Client and server project I made. If many Client need to connect to one server, I created many thread to handle many different Client.
@arijitdas3958
@arijitdas3958 2 жыл бұрын
Hit like to SUPPORT HIM, If you believe HE IS THE LIFE SAVER !!!!!!!
@sanayasamadhi70
@sanayasamadhi70 Жыл бұрын
amazing video.u make my day
@percivalgebashe4376
@percivalgebashe4376 Жыл бұрын
Nice
@ahmadal-hafi580
@ahmadal-hafi580 2 жыл бұрын
Yooo U have a great way for explaining!
@jrd3uCe
@jrd3uCe 10 ай бұрын
I will forever keep coming back to your page for review and better understanding
@mateskyjanica7696
@mateskyjanica7696 Жыл бұрын
Good job, Bro
@darianchan4649
@darianchan4649 3 жыл бұрын
awesome tutorial!
@matteocamarca
@matteocamarca 6 ай бұрын
Priceless. Thanks.
@JohnWickXD
@JohnWickXD 2 жыл бұрын
OP stuff vrooo
@NHCS_AMOGH_PATIL
@NHCS_AMOGH_PATIL 2 жыл бұрын
Bro you are great bro
@AbhijeetKumar-cm3jh
@AbhijeetKumar-cm3jh 3 жыл бұрын
Thanks BRO !!
@user-ke6vc7pk6x
@user-ke6vc7pk6x Жыл бұрын
very useful video
@user-ke9vd6mx1n
@user-ke9vd6mx1n 9 ай бұрын
best explanation!
@oscarjosefsson9300
@oscarjosefsson9300 Жыл бұрын
So I guess this is normal. But I still got confused. Because when thread2 starts you can no longer know for sure in which order things will happen. Sometimes thread 2 will finish before you have time to check if it is running or how many threads are running. And sometimes it will still be alive when you check it. Try adding a few more printline statements in both threads. Quite interesting to see how it will sometimes execute one line of code from one thread then jump to the other thread and so on. Also when making thread2 a daemon thread there is actually no guarantee that it will have time to execute all of its program before the Main thread finishes and thus shuts down the program!
@calor6990
@calor6990 Жыл бұрын
Thank you friend!
@GraceHerbert-bk4it
@GraceHerbert-bk4it Жыл бұрын
Awesome as usual!
@waedradi8552
@waedradi8552 9 ай бұрын
Thanks bro One of the best 👏🏼
@chocodonuts3644
@chocodonuts3644 9 ай бұрын
helpful
@magxbeats
@magxbeats Жыл бұрын
Good sir 👍
@AEINTech
@AEINTech 3 жыл бұрын
Great video : )
@faizalimuhammadzoda4731
@faizalimuhammadzoda4731 2 жыл бұрын
Thanks for the effort. Appreciate it.
@esthermdzitiro31
@esthermdzitiro31 3 жыл бұрын
Great video
@lilit3552
@lilit3552 2 жыл бұрын
This was well explained informative lesson. Thank you!
@user-hr9dj3gm5u
@user-hr9dj3gm5u 2 жыл бұрын
It is good explenation i have ever listened
@faizalimuhammadzoda4731
@faizalimuhammadzoda4731 2 жыл бұрын
Thanks for sharing!
@blabberq
@blabberq 2 жыл бұрын
Simple, good explanation :)
@tanushthiru3389
@tanushthiru3389 7 ай бұрын
good vid 👍
@oguzhantopaloglu9442
@oguzhantopaloglu9442 3 жыл бұрын
extremely informative!
@xpolentaedgex
@xpolentaedgex 2 жыл бұрын
thanks for the class Bro
@ajaykotian5
@ajaykotian5 2 жыл бұрын
Thank you for posting this -- the video is extremely useful.
@MrLoser-ks2xn
@MrLoser-ks2xn 2 жыл бұрын
Thanks
@behrangfattahi9328
@behrangfattahi9328 2 жыл бұрын
Tnx bro you are the best
@user-oe8es7hu5h
@user-oe8es7hu5h 8 ай бұрын
That's cooool!
@shaynazoedeguzman7418
@shaynazoedeguzman7418 2 жыл бұрын
Two thumbs up! 👍👍
@Monsta1291
@Monsta1291 2 жыл бұрын
amazing
@ruantristancarlinsky3851
@ruantristancarlinsky3851 2 жыл бұрын
Excellent video. Semester just started and this video really helped me out a lot man!. Please be sure to continue making more videos. Thanks
@osazeimohe7745
@osazeimohe7745 2 жыл бұрын
Thank you
@ivy267
@ivy267 2 жыл бұрын
thx a lot bro
@abdullahalmahmud2146
@abdullahalmahmud2146 2 жыл бұрын
awesome
@essaalu7047
@essaalu7047 3 жыл бұрын
useful 👍💙
@ofiregev
@ofiregev 2 жыл бұрын
great video ! thank you very much !
@girl6994
@girl6994 4 жыл бұрын
Liked, by the way , there are so many people
@-zokzok-9455
@-zokzok-9455 2 жыл бұрын
that was awesome thank you sensei
@AVGilboa
@AVGilboa 2 жыл бұрын
thank you!
@thangavelpetchiappan4689
@thangavelpetchiappan4689 2 жыл бұрын
well explained.. :)
@SpidahRidah
@SpidahRidah 3 жыл бұрын
Excellent video. Thank you.
@Makariush
@Makariush Жыл бұрын
THX
@sofianealloui
@sofianealloui Жыл бұрын
BRO ♥
@pitched7401
@pitched7401 Жыл бұрын
I was wondering something about the run method. Why is it not always necessary to implement the Runnable interface? I often see threads getting created with the Runnable interface or the corresponding lambda expression. If the Thread class already has it's own "run" method, why do people implement the Runnable interface seperately?
@tuanhungpham449
@tuanhungpham449 3 жыл бұрын
Thanks bro
@yahelbraun5471
@yahelbraun5471 4 жыл бұрын
Can you make a video about @Override?
@BroCodez
@BroCodez 4 жыл бұрын
kzbin.info/www/bejne/iKGrZmOZZ79gfsU
@yahelbraun5471
@yahelbraun5471 4 жыл бұрын
@@BroCodez thank you! Very good explanation!
@Momo-qr3rd
@Momo-qr3rd 3 жыл бұрын
Thank you Bro :)
@vitor1678
@vitor1678 2 жыл бұрын
I'm dropping a comment down below for Bro.
@MrLoser-ks2xn
@MrLoser-ks2xn Жыл бұрын
@harshith_takkala
@harshith_takkala 3 жыл бұрын
Hey thanks But at the second println statement of thread.active count, I am getting 1 sometimes and 2 sometimes Why? I have started the thread 2 also
@carlosbernardo6531
@carlosbernardo6531 2 жыл бұрын
@gogoi.
@gogoi. 3 жыл бұрын
Thank You
@nehalayaaz9406
@nehalayaaz9406 4 жыл бұрын
Thanks 😊
@kippenvogelchen9717
@kippenvogelchen9717 3 жыл бұрын
nice!
@krishp2321
@krishp2321 3 күн бұрын
What is the purpose of threads?
@_sf_editz1870
@_sf_editz1870 2 жыл бұрын
I want to be a fellow bro
@manuelgonzalezpalafox2627
@manuelgonzalezpalafox2627 Жыл бұрын
Ly bro 12
@yahelbraun5471
@yahelbraun5471 4 жыл бұрын
I don't understand what is a thread.. can someone explain?
@BroCodez
@BroCodez 4 жыл бұрын
A thread is a single sequential flow of control within a program
@NguyenMinhuc-ss2cs
@NguyenMinhuc-ss2cs 10 ай бұрын
ok
@kemann3815
@kemann3815 2 жыл бұрын
Another banger
@gustavokenzomiyamoto2434
@gustavokenzomiyamoto2434 Жыл бұрын
What is the relationship/difference between threads and methods (and classes)?
@tharinduperera8758
@tharinduperera8758 Жыл бұрын
Methods are actions that need to be taken place.. you can implement anything to do within the method. Let's say you need to execute that method 5 times in parallel. Then you can use threads.. threads will execute your method number of threads you have defined simultaneously.. if you did this using a loop it will execute one after another. Threads likes number of people doing the same function at the same time..instead of one handling the heavy load , multiple threads can handle the work load faster and efficiently with the cost of memory usage. And as bro taught you can use the thread execute the method or certain function with a certain time interval and so many other functions
@redazaidane6780
@redazaidane6780 2 жыл бұрын
halo
@ponanbalagan2988
@ponanbalagan2988 3 жыл бұрын
My query is how to add JFrame in database please answer bro code
@BroCodez
@BroCodez 3 жыл бұрын
I haven't covered SQL yet, that may require a video to explain
@Origon09
@Origon09 2 жыл бұрын
14:08 when you are using the run method. How does the method know which thread it is checking?
@Origon09
@Origon09 2 жыл бұрын
couldn’t it be checking the main thread and not the one you just created?
@danielmilewski7659
@danielmilewski7659 2 жыл бұрын
comment for stats
@CJDaBomb69
@CJDaBomb69 Жыл бұрын
How did you get your console text to be that colour?
@zari_723
@zari_723 Жыл бұрын
hi
@davidgonzalez-ge7ol
@davidgonzalez-ge7ol 2 жыл бұрын
GOLD
@user-sb9ld7ul5b
@user-sb9ld7ul5b 7 ай бұрын
just "bro"
@kristjantoplana2993
@kristjantoplana2993 5 ай бұрын
HELLOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
@Bladermishal10
@Bladermishal10 3 жыл бұрын
hmmm so the when you call a thread it just runs all the functions? because you didnt call the run function
@tobrojekt27
@tobrojekt27 3 жыл бұрын
if i set thread2 to daemon, it did not show up the message, that it is a daemon thread that is running. I needed to add thread2.join; after the thread2.start; statement, in order to execute the run() function of thread2 somehow
@tobrojekt27
@tobrojekt27 3 жыл бұрын
and i dont know why it workd for u but not for me without the thread2.join
@kristjantoplana2993
@kristjantoplana2993 5 ай бұрын
HELLOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
@YassineTamam
@YassineTamam Жыл бұрын
slay
Java multithreading 🧶
15:18
Bro Code
Рет қаралды 125 М.
Parenting hacks and gadgets against mosquitoes 🦟👶
00:21
Let's GLOW!
Рет қаралды 13 МЛН
Son ❤️ #shorts by Leisi Show
00:41
Leisi Show
Рет қаралды 10 МЛН
If Barbie came to life! 💝
00:37
Meow-some! Reacts
Рет қаралды 68 МЛН
Java generics ❓
22:04
Bro Code
Рет қаралды 106 М.
Generics In Java - Full Simple Tutorial
17:34
Coding with John
Рет қаралды 1 МЛН
Advice for Writing Small Programs in C
1:45:24
Sean Barrett
Рет қаралды 142 М.
How I program C
2:11:32
Eskil Steenberg
Рет қаралды 729 М.
Java HashMap 🗺️
13:05
Bro Code
Рет қаралды 80 М.
Crust of Rust: async/await
2:34:01
Jon Gjengset
Рет қаралды 189 М.
Multithreading in Java Explained in 10 Minutes
10:01
Coding with John
Рет қаралды 909 М.
Parenting hacks and gadgets against mosquitoes 🦟👶
00:21
Let's GLOW!
Рет қаралды 13 МЛН