ISO 9001:2015 Certified Company

Sukrala IT Services Pvt. Ltd.,
SCO 23-24-25, Level 3rd,
SEC 34-A, Chandigarh.
Phone: 99-88-74-1983, 0172-503-1983

Multithreading

  • 0

Multithreading

Multithreading in Java

Multithreading is a process of executing multiple threads concurrently.
It is a combination of Multi + threading, where multi means multiple and thread means sub_process.

So, before understanding thread we should first understand what is process, as thread is a sub process means a part of a process.

Multithreading

Process:

Definition : Exceutable state of a program is known as process.
That means, everything that system (Computer) execute is known as process e.g, playing music, working with software like Microsoft word document, playing game etc are the examples of process.

Each process is a combination of one or more than one thread(s).

e.g; Microsoft office word document : It consists of multiple threads like one thread take the keyboard information for displaying content and simultaneously another thread do check on the content spelling.

So from above content we came to know that multiprocessing and multithreading both are part of multitasking.

Difference between Multiprocessing and MultiThreading :

Multiprocessing Multithreading
Multiple process have their own memory location, as different software has different memory allocation in our. As thread is a subpart of process it shares common memory allocation as that of process.
As process are on different memory location therefore context switching time(time taken by processor to move from one process to another to allocate resources) is more. Where threads has very small context switching time.

Multithreading is mostly mostly used in games,animation.

Thread:

Definition : Thread is a light weighted sub-process.

Threads in java :
There are two ways to implement threads in java:

  • By extending Thread class
  • By implementing Runnable interface

Thread class is a predefined class in java heaving multiple methods to start and execute threads.

Whereas runnable is an Interface heaving run method only.

As java doesn’t support multiple inheritance with classes, it always provide an alternative to perform multiple inheritance with interface (as in case of multithreading it provide Runnable interface).

Example: with Thread class

Class ThreadDemo extends Thread
{
Public void run()
{
System.out.println(“Thread Execution code”);
}
Public static void main(String args[])
{
ThreadDemo a = new ThreadDemo()
a.start();
}
}

Example: with Runnable interface

Class ThreadDemo implements Runnable
{
Public void run()
{
System.out.println(“Thread Execution code”);
}
Public static void main(String args[])
{
ThreadDemo a = new ThreadDemo();
Thread t1 = new Thread(a);
t1.start();
}
}

Working of thread:
Threads complete its process or execution in five steps, known as life cycle of thread.

Java Thread state are as follows:

  1. New
  2. Runnable
  3. Running
  4. Non-Runnable
  5. Terminate

android training in Chandigarh - multithreading

  1. New -> Thread is in new state when we create an instance of thread class.
    e.g ThreadDemo a=new ThreadDemo(); //in case of extending thread;

    Thread t1=new Thread(a); //in case of implementing interface.

  2. Runnable -> Thread is ready to run but waiting for resource allocation.
    i.e when we call start() method in program.
  3. Running -> When resources are allocated to thread..
    when start() method finds run() method // backend task
  4. Non-Runnable/ blocked -> when thread is alive, but due to some reasons not eligible to run.
  5. Terminate -> Either Thread execution is completed or forcefully terminated.

When we want to create animated screens for android application, then we use multithreading concept. Android training in Chandigarh help you to create animated screen while creating android mobile applications.

Facebook Comments


Contact Us

PHP Training in Chandigarh

PHP Training in Chandigarh
Rated PHP training in Chandigarh 5/5 based on 9963 reviews

Facebook Comments

Facebook Comments

Student Testimonial

Chandigarh’s First Youtube Channel-Video Management Laboratory Setup

Adwords video Certification

SEO courses in chandigarh

Adwords Search Certificate

best seo training institute in Chandigarh

Adwords Shopping Certification

SEO course in chandigarh

Adwords Display Certification

SEO course in chandigarh

Google Analytics Certification

Best SEO training in chandigarh

Bing Ads Certification

digital marketing course in chandigarh
error: Content is protected !!