Posts

Showing posts with the label Multithreading

daemon thread

What is a daemon thread            Daemon threads are sometimes called "service" threads. These are threads that normally run at a low priority and provide a basic service to a program or programs when activity on a machine is reduced.           An example of a daemon thread that is continuously running is the garbage collector thread. This thread is provided by the JVM.

difference between yield and sleeping

What is the difference between yield and sleeping When a task invokes yield(), it changes from running state to runnable state. When a task invokes sleep(), it changes from running state to waiting/sleeping state.

Thread Life Cycle in java

Image
Thread Life Cycle -      In the following figure, we are describing about Thread Life Cycle. 1) Create Thread – Thread can be create through Thread Class or Runnable interface. 2) New State – when any object of thread is being made by new Thread() 3) Runnable – When start method of thread is called means thread is now in runnable state. 4) Running – After Runnable state, based on the priorities of thread, is being to running state. 5) Dead – After running state, thread will go to Dead. Or it can be block states. 6) Block States – Thread can be in block state by calling wait(), sleep(), join() methods. 7) Sleep State – when sleep() method is called by thread, thread will go to the sleep state. Sleep State means, This thread is still alive and it can be go on runnable state. Thread has sleep method for passing the time in millisecond. And throw InterruptedException.     static void sleep(long millisecond) throws Int...

Creating a Java Thread example

Creating A Thread - There are two ways to create threads. 1)extends Thread Class 2)implements Runnable Interface. Example – Through the Thread Class public class Test extends Thread{     private String msg;         Test(String msg){         this.msg=msg;     }     public void run() {         for(int x=0; x<5; x++){             System.out.println("-----"+msg);         }     }     public static void main(String[] args){         Thread thread1 = new Test("first Thread");         Thread thread2 = new Test("Second Thread");         thread1.start();         thread2.start();     } }  Example...

about Process And Thread java

Process And Thread When program runs under the concurrency environment, Then Thread will be in lead roles. Environment which manages some threads called process. Threads – Thread are light weight piece of code which runs under the concurrent environment. Many threads can run concurrently and share the same heap memory but every thread has its own stack allocation area. Threads can run under the process. Process – Process is an execution of program and has its own memory allocation areas. A JVM runs in a single process and threads runs under the JVM and share a single heap memory allocation area. Threads exist within a process — every process has at least one. Threads share the process's resources, including memory and open files. This makes for efficient, but potentially problematic, communication.

Recent Post

Recent Posts Widget