#1 Mastering Threads in Java Running and Blocking Explained

preview_player
Показать описание
You know that run is the method that is used to run the thread What I can do here for int i is equal to one I less than equal 3 I plus plus So each thread will run how many times 3 times 2 Each thread run 3 times Thread dot current thread How can I extract I already covered there is a static method is available in the thread class that is current thread that returns me the object of the currently running thread Now fine if it is the first thread running first thread object is returned the name is first second thread running second third thread running the name is third How can I get it uh stream Name is equal to string name is equal to tt dot that is the get name tt dot get name It returns me word that is the name of the thread which is running That is the I just write here system dot out dot that is the println I just write here running thread name is running thread name is fine plus what's I write here Name plus what's I write here Is it over If it is the first thread running thread name is first colon I value is word 1 I want to block the running thread for one second How can you block Within the try block I just write the code Because slip method I already detect uh throws one exception What are the exception it throws Uh interrupted exception I just write here That is fine Thread slip That is one thousand millisecond Now see which thread is running that's not a matter That thread is blocked uh for how many seconds Because it is a static method Static method can be implemented on any object If it is the first thread is running that is blocked for one second When the first thread is blocked for one second is it wetted or called the next thread Called the next thread
Рекомендации по теме