Java thread class methods and its function
Thread class contains different methods, using these methods we can manipulate the thread.
Some methods are given below.
Thread class methos and its funtion
start()---->A thread execution started from the start() method,unless you implement the start() method thread will not be started.
run()----> implicitly called by the start() method
sleep(milliseconds)---->suspends the thread for given milliseconds of time,This should be written in the try catch block as the exception occurs.This is a static method,So this method can be called directly.
join()---->waits the thread to complete its process,used in multi threading,it should be written in the try catch block as the exception occurs.This is a static method,So this method can be called directly.
getId()---->Gives the ID of the thread
getName()---->Gives thread names,always start from thread-0
setName(sting)---->Thread name will be replace with given string
getPriority()---->This method returns the thread priority.Every java thread has a priority between 1 and 10, and by default each thread is given normal priority,that is ,5.
setPriority(integer)---->To set the priority of the thread.
isAlive()---->This method determines whether the thread is still running or not.It returns true or false.Returns true if the thread is running and false if the thread process is complete.
Remember the naming convention of java programming
Two static methods of thread class in java
sleep(milliseconds)---->suspends the thread for given milliseconds of time,This should be written in the try catch block as the exception occurs.This is a static method,So this method can be called directly.
join()---->waits the thread to complete its process,used in multi threading,it should be written in the try catch block as the exception occurs.This is a static method,So this method can be called directly.
Comments
Post a Comment