Posts

Showing posts with the label Thread

Thread priority in java with example

Thread priority is useful to maintain threads in an order in java. When multiple threads are created and started, a 'Thread Scheduler' program will load all threads into JVM memory and executes them based on thread priority. This scheduler will allot more JVM time to those threads which are having higher priorities.           The priority number of a thread will change from 1 to 10. The minimum priority ( Thread.MIN_PRIORITY ) of a thread is 1, and the maximum priority ( Thread.MAX_PRIORITY ) is 10. The normal priority of a thread ( Thread.NORM_PRIORITY ) is 5. Example: Let us write a program to understand the thread priority. The thread with higher priority number will complete its execution first. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 package com . javatbrains . threads ; class ThreadPriority extends Thread { int count = 0 ; publi...

Threads in java with example

Image
Read this article to know what is thread and what is the lifecycle of thread in java. Threads concept introduced in java to achieve multiprocessing. Thread represents a separate path of program execution. All threads are running on top of the Main thread in java. This main thread is called daemon thread. Explanation: A thread represents a separate path of execution of a group of statements. In a Java program, if we write a group of statements, then these statements are executed by JVM one by one. This execution is called thread, because JVM uses a thread to execute these statements. This means in every Java program there is thread is running internally. Let us see the below program to find the thread used by JVM to execute the statements: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 package com . javatbrains . threads ; public class CurrentThread { public static void main ( String [] args ) { System . out . println ( "Let us f...