Monday, 18 November 2019

SE - 39 - Some basics about thread in Java

Lets see some of the basics about thread in java :

1) Thread can't be started twice. It can be started only once by using start() method. If we attempt to start the thread twice we get IllegalThreadStateException.

2) We can create Thread in Java in 2 ways :
     a) By implementation of Runnable class
     b) By extending Thread class

3) Only start() method is used to start the thread. If we call the run() method then the Thread will not be called rather it will behave as normal method calling

4)  Suppose if there is any statement written (Eg : printing some text , etc) after start() method in thread then in output we will see the thread initiated after the execution of next statement.  Java will execute the next statement then start the thread.

No comments:

Post a Comment