Mutithreading- Thread class

Mutithreading- Thread class

The multithreading system of java is built on thread class, its methods and runnable interface.

The execution of threads are encapsulated under Thread. In order to create a new thread, one can either extend the existing thread or implement the runnable interface.

The Thread class implements several class that should be used when working with thread. The methods are listed below

[table “” not found /]

We shall see implementation of above methods.

Example-

getCurrentThread

Output

In the example above we see that it displays current thread output in a certain ways.

The element at first index location “main” is name of the thread, element at second location “5” is the default priority, and the element at last index location “main” is the name of group to which the thread belongs. A group thread is a data structure which controls the state of collection of threads as a whole.

Let us see implementation of few more methods to understand better.

Output

 

Leave a Reply

Your email address will not be published. Required fields are marked *