- Java Programming Examples
- Example - Home
- Example - Environment
- Example - Strings
- Example - Arrays
- Example - Date & Time
- Example - Methods
- Example - Files
- Example - Directories
- Example - Exceptions
- Example - Data Structure
- Example - Collections
- Example - Networking
- Example - Threading
- Example - Applets
- Example - Simple GUI
- Example - JDBC
- Example - Regular Exp
- Example - Apache PDF Box
- Example - Apache POI PPT
- Example - Apache POI Excel
- Example - Apache POI Word
- Example - OpenCV
- Example - Apache Tika
- Example - iText
- Java Tutorial
- Java - Tutorial
- Java Useful Resources
- Java - Quick Guide
- Java - Useful Resources
How to set the priority of a thread in Java
Problem Description
How to set the priority of a thread?
Solution
Following example how to set the priority of a thread with the help of.
public class new_file { public static void main(String[] args) throws Exception { Thread thread1 = new Thread(); Thread thread2 = new Thread(); thread1.setPriority(Thread.MAX_PRIORITY); thread2.setPriority(Thread.MIN_PRIORITY); thread1.start(); thread2.start(); thread1.join(); thread2.join(); System.out.println("The priority has been set."); } }
Result
The above code sample will produce the following result.
The priority has been set.
java_threading.htm
Advertisements