RUVIDEO
Поделитесь видео 🙏

java 43 | Thread class methods | Thread class constructors | sleep(), join () | setName (), setId()

📁 Лайфстайл 👁️ 16 📅 05.12.2023

Thread class provide constructors and methods to create and perform operations on a thread.
Thread class extends Object class and implements Runnable interface.
At the end of this class students will be able to understand:-
Thread class constructors
Thread class methods
Following is the declaration for java.lang.Thread class −

public class Thread extends Object implements Runnable
{
….
….
}
Thread class extends Object class and implements Runnable interface
constructors
Thread()
Thread(String name)
Thread(Runnable r)
Thread(Runnable r,String name)
Methods
currentThread( ): java.lang.Thread.currentThread() Returns a reference to the currently executing thread object
Syntax:
public static Thread currentThread()
Returns: the currently executing thread


run(): java.lang.Thread.run()
Syntax:
public void run()
Description: If this thread was constructed using a separate Runnable run object, then that Runnable object's run method is called; otherwise, this method does nothing and returns. Subclasses of Thread should override this method.
start(): java.lang.Thread.start() Causes this thread to begin execution; the Java Virtual Machine calls the run method of this thread
Syntax:
public void start()
Throws:
IllegalThreadStateException - if the thread was already started.

getName(): java.lang.Thread.getName() Returns this thread’s name
Syntax:
public final String getName()
Returns: this thread's name

getId(): java.lang.Thread.getId() Returns the identifier of this Thread
Syntax:
public long getId()
Returns: this thread's ID

setName(String name): java.lang.Thread.setName(String name) Changes the name of this thread to be equal to the argument name.
Syntax:
public final void setName(String name)
Parameters: name - the new name for this thread.
Throws: SecurityException - if the current thread cannot modify this thread.

isAlive(): java.lang.Thread.isAlive() Tests if this thread is alive
Syntax:
public final boolean isAlive()
Returns: true if this thread is alive; false otherwise

getPriority(): java.lang.Thread.getPriority() Returns this thread’s priority
Syntax:
public final int getPriority()
Returns: this thread's priority

setPriority(int newPriority): java.lang.Thread.setPriority(int newPriority) 
Changes the priority of this thread
Syntax:
public final void setPriority(int newPriority)
Parameters: newPriority - priority to set this thread to Throws:
IllegalArgumentException- If the priority is not in the range MIN_PRIORITY to MAX_PRIORITY
SecurityException - if the current thread cannot modify this thread.

join(): java.lang.Thread.join() Waits for this thread to die
Syntax:
public final void join() throws InterruptedException
Throws:
InterruptedException - if any thread has interrupted the current thread. The interrupted status of the current thread is cleared when this exception is thrown

join(long millis): java.lang.Thread.join(long millis) Waits at most millis milliseconds for this thread to die
Syntax:
public final void join(long millis) throws InterruptedException
Parameters: millis - the time to wait in milliseconds
Throws:
IllegalArgumentException - if the value of millis is negative InterruptedException - if any thread has interrupted the current thread. The interrupted status of the current thread is cleared when this exception is thrown.

sleep(long millis): java.lang.Thread.sleep(long millis) Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds, subject to the precision and accuracy of system timers and schedulers
Syntax:
public static void sleep(long millis) throws InterruptedException Parameters: millis - the length of time to sleep in milliseconds Throws: IllegalArgumentException - if the value of millis is negative
InterruptedException - if any thread has interrupted the current thread. The interrupted status of the current thread is cleared when this exception is thrown.

summary
Thread class provides constructors and methods to create and perform operations on a thread to:-
Create and Run the thread
Set the name and id of thread
Get the name and id of the thread
Set the priority of the thread
To put itself to sleep and join after other thread is dead

list of suggested reading
Java: The Complete Reference Book by Herbert Schildt
https://www.youtube.com/playlist?list=PLA3taA2THXpy0q0TxYd4i5dpk76HpsZ_n
https://www.geeksforgeeks.org/java-lang-thread-class-java/

Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «java 43 | Thread class methods | Thread class constructors | sleep(), join () | setName (), setId()», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.

Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.

Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!

Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.