Thread Life Cycle in Java

Thread Life Cycle in Java tells the various information of thread form born to terminate. Thread life cycle contains the several stages and at a time any thread can be present  in a single state. States of Thread life cycle Born Ready Running Blocked Sleep Wait Dead Ready:  In this state thread is ready to … Read more

Thread isAlive() and join() Methods in Java

There are two ways  to determine whether a thread has finished or not.   isAlive()   join() isAlive():  isAlive() method is used to check whether a thread is in the running or not .                                                 or In a another word, this method determines thread is live or dead.  isAlive( )method returns true if the thread … Read more

Thread suspend() and resume() method in Java

suspend() : This method suspend a thread for sometime but do not kill/terminate it. resume() : This method revives the suspended thread.

Thread stop method in Java

In java, stop()  method  kills/terminates  the currently executing thread.

Result

Description: in the above program, when value of variable i=3 then stop() method terminates the curently executing thread and come out of the loop.

Thread Yield method in Java

In java, yield()  method  temporarily pause  the currently executing thread object  and allow other threads to execute.

Producer Consumer Problem in Java

In computing, producer–consumer problem also known as the bounded-buffer problem. In the producer–consumer problem there are two processes, first is producer and the second is consumer, who share a common, fixed-size buffer.  The producer’s job is to generate data, put it into the buffer and start again. At the same time, the consumer’s job is … Read more

Thread Synchronization in Java

When two or more threads try to access the same resource, they need somehow to ensure that the resource will be used by only one thread at a time. The process by which this achive is called Synchronization. Java uses the concept of monitor (also called semaphore) for Synchronization. The monitor allows one thread at … Read more

Thread Priorities in Java

In java, when two or more than  two thread is computing for CPU time, every thread is assigned a priority value. A highest Priority thread get preference over lower priority thread.   All Java threads have a priority in the range 1-10. Top priority is 10, lowest priority is 1.Normal priority ie. priority by default … Read more

Main Thread in Java

In Java programming, when a program begins the first thread that starts running is called main thread.  Other threads(child thread) can be spawned from this main thread. When program terminates, the main thread must be the last thread in the program to end. When the main thread stops, the program stops running. Main thread is … Read more