Saturday, 25 December 2021

Thread class methods in java

The following are the some important thread class methods available in java.lang.Thread class

To create a thread we can use the formats 

Thread t1=new Thread();

Thread t2=new Thread(obj);

Thread t3=new Thread(obj, "Thread name");

 


1. To know the currently running thread

      Thread t=Thread.currentThread();

2.To start a thread

  t1.start()

3.To stop execution of a thread for a specific time

Therad.sleep(milli seconds)

4. To get the name of thread

String name =t1.getName();

5. To set a new name to a thread

 t1.setName("new name);

6. To get the priority of thread

int a=t1.getPriority();

7. To set new priority() for a thread

t1.setPriority(int priority_no)

8. When a high priority thread comes into running state, if already running threads have low priority the newly coming thread then it yields to runnable

t1.yield()

9. If you want to stop a thread from newborns state, runnable state invoke stop() method on that thread.

t1.stop()


0 comments:

Post a Comment

Note: only a member of this blog may post a comment.

Find Us On Facebook

Computer Basics

More

C Programming

More

Java Tutorial

More

Data Structures

More

MS Office

More

Database Management

More
Top