CodesJava

Easy learning with example program codes

Commonly used methods of Thread class


1. public void start()

starts thread to begin execution, JVM calls run method of this thread.

IllegalThreadStateException – if the thread was already started.

2. public void run()

run method is used to perform operations by thread.

3. public final void setName(String name)

Changes the name of the thread.

name – new name for this thread.

4. public final String getName()

Returns this thread’s name.

5. public final void setPriority(int newPriority)

Changes the priority of the thread.

IllegalArgumentException – If the priority is not in the range MIN_PRIORITY to MAX_PRIORITY.

6. public final int getPriority()

Returns thread’s priority.

7. public final void join()

The current thread invokes this method on a second thread, causing the current thread to block until the second thread terminates.

8. public final void join(long millisec)

The current thread invokes this method on a second thread, causing the current thread to block until the second thread terminates or the specified number of milliseconds passes.

9. public final void setDaemon(boolean on)

Marks this thread as daemon thread if on is true.

10. public final boolean isDaemon()

Returns true if thread is daemon.

11. public final boolean isAlive()

returns true if thread is alive.

12. public long getId()

Returns the ID of the thread(A long number generated at the time of thread creation).

13. public void interrupt()

Interrupts this thread and causing it to continue execution if it was blocked.

14. public boolean isInterrupted()

Returns true if thread is interrupted else return false.

15. public static void dumpStack()

Prints a stack trace of the current thread.

16. public static void sleep(long millis)

Causes the currently executing thread to sleep for the specified number of milliseconds.

17. public static void yield()

Causes the currently executing thread object to temporarily pause and allow other threads to execute.

18. public static Thread currentThread()

Returns a reference to the currently running thread.
 
Next Topic: Thread scheduling in java with example.
Previous Topic: Way of creating thread in java.

Related Topics:

Core Java Tutorial

Programming language overview.
Overview of Java.
Java features
JVM architecture details.
JVM, JRE and JDK.
Java Coding Guidelines.
Some important definitions.
Variable and data types.
Hello world java program.
Core java examples programs.
Important Java Programs.
How to set permanent path in java?
OOPs Basics.
Object and Class in Java.
OOPs Principles/Concepts.
Abstraction in java.
Encapsulation in java.
Polymorphism in java.
Method overloading in java.
Method overriding in java.
Dynamic method dispatch.
Runtime polymorphism.
Association in java.
Inheritance in java.
Aggregation in java.
Command line arguments in java.
Command line argument program in eclipse.
Read input from command line using Scanner.
Java array programs
Java star pattern programs
Java number pattern programs
final in java.
Abstract class in java.
Interface in java.
Custom marker Interface in java.
Constructor in java.
Package in java.
Access modifier in java.
Static import in java.
Package class in java.
this in java.
Instance initialize block.
Anonymous block.
super in java.
Static in java.
final in java.
Java cloning deep and shallow
Shallow vs Clone copy
String handling in java.
String handling programs.
StringBuffer in java.
StringBuilder in java.
Exception Handling Tutorial.
Multithreading Tutoial.
Java input output stream tutorial.
Collections framework in java tutorial.
Collections framework programs.
Java Random class
Java annotations.
Java design principles.
Java 7 features
Java 8 features
Java networking tutorial
Java Reflection tutorial
Sign Up/ Sign In
Ask a Question


Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at hr@codesjava.com.

Development

We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on hr@codesjava.com.

Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki