Multithreading
  • -

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.


Contact Us

    PHP Training in Chandigarh

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

    Python Training in Chandigarh

    Python Training in Chandigarh

    Rated Python Training in Chandigarh 5/5 based on 16769 reviews

    Graphic Designing Course in Chandigarh

    Best Graphic Designing Course in Chandigarh

    Rated Best Graphic Designing Course in Chandigarh5/5 based on 9669 reviews

    Coding Classes in Chandigarh

    Coding Classes in Chandigarh

    Rated Coding Classes in Chandigarh5/5 based on 9696 reviews

    Java Training in Chandigarh

    Java Training in Chandigarh

    Rated java Training in chandigarh5/5 based on 15933 reviews

    Data science course in Chandigarh

    Data science course in Chandigarh

    Rated Data science course in Chandigarh5/5 based on 9936 reviews

    Cloud Computing Training in Chandigarh

    Cloud Computing Training in Chandigarh

    Rated Cloud Computing Training in Chandigarh5/5 based on 15933 reviews

    UI UX Design Course Chandigarh

    UI UX Designing Course in Chandigarh

    Rated UI UX Design Course Chandigarh 5/5 based on 9699 reviews

    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

    Industrial Training

    Nothing is more Expensive than a missed Opportunity.

    Let us know

    your Customized Requirement,
    our Course Advisors are there to Serve You.!!

      no thanks

      error: Content is protected !!