was gone as welcomes your second tutorial in java game development
and in this story wrongly actually finishing up the last story re pretty
much argun finish creating a
to read and well let's just go ahead and get started
so actually we need a main method in there so let's go ahead and I probably
should done that before
but I can do now published static void
main stirring my heart's
arch stadiums go ahead and put main matter to rate their
so in our main matted again I should done that before but oh well
you guys ass in time what you need to do in order to make threats
is call caps lock on the up
is to read class go ahead and both red and then a mentor and I'm gon a mighty
one
and said he quit in New to read but as your parameter
for this third class yes to rate the object that you want to treat
as a dread sewed new Apple remember I made this Apple class rehear their organ
meat reading is a thread
and the constructor took a pram nerd and I'm can name it
1 so this thread that has the variable t1
is gon be named one so let's go ahead and make
two more right now arm again we're gon be creating three threads
from the same class in a min im this want t2
and the variable 23 in threads name is going to me
to and three
and if your honor I and type in 1 2-3 it's because this
Apple constructor remember we passed in a string variable to give a name
right there and then arm upon to show action and object to create a random
time
so now that we have left to read
this pretty much means each of these things
instead running array after another like they would have their just
a regular object they can all run at the same time
so before we learned about threads
whenever we created a new Apple class it would have to do the constructor
into everything ended first before moving on to this one and then
after that in mood and this one but
now now we have three threads and several one long program in essence
this is three things running at the same time
so we get some three times as fast is a usually would
sahnoun that we have a thread
we need to start it so what star
whenever we costar the objects or threads run
is on Mac league can be called we don't have to call Ron
we all we have to do is call star in any cold in here
in thread to run is gonna on Mac would be called
so how do we do that all we do is t1 dot
start to rate their in this is gonna start a thread or in other words start
the code in here
so t1 just copy this t2
nt-3 and why did I make this ran a time
washoe your eye in a second if I go ahead and click his application
run it and I forgot to put
a new line rehear an embarrassing in Alameda mystery that again
it says one
is sleeping 4 for 19 three is sleeping
for 876 and to is sleeping for 189
interest in Ari why doesn't he just go 1-2-3
well that's because your computer dozen
do in it doesn't have to do when you create threads
in order one right after another and that's the beauty of threats
these pretty much star all at the same time
arm I mean there's little bit different by in essence they all started the same
time
and why did I put how long sleeves for because
wanna Brent sleeps it pretty much does nothing
but wait there it doesn't arm poll burden on your CPU processor no
it just sits there in weights their in
it pretty much the last for other stuff to happen suffer centauri
when this thread is done I want you to sleep in wafer other threats
so well went to his sleeping a pretty much just sittin there
in chilling so that's why once each for attentive or exceeding like a twenty
years
or .1 a up a sec in then this one gets done sleeping first
the next one to wake up is train number one because
it slut a medium amount of time but three it was a lease in the side is
sleep the longest
that's why three got done running so late so again
but i wanna demonstrate is instead going ray after another one
to 3 these things run pretty much
out the same sup same time so it's pretty much a randomized
11 is gonna be your first and this is also a random and I wanna
display this because arm this says Wallace sleeping
it allows other threads to continue doing what they do
so this is kinda the beauty of threads one more time there
you can have multiple things running at the same time
in this speeds up your program that's all I want explain for this story I'll
there is a ton more to go over in threads but for
arm the second this store oh that's all we need to know for now
as we continue programming in games will learn later and even that this doesn't
make sense now when I start using in the game
sometimes Aegis examples using it can be kinda makes using cuz it doesn't really
do anything is just an example
but trust me why you'll see why this is useful later on
by needed to give you guys a quick intro or routes I would never forgive myself
for
so that's all you need to know about threads for now if you wanna learn more
than got the job a website or something or just wait for my tutorials
but for now thank yes ru watchin I don't get check out the next door to where we
will be pretty much
building our very first beginning have a job a game
so thank you again don't you subscribe to now see next door