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 :

MultiprocessingMultithreading
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 Video

    Python Training In Chandigarh

    CBitss offers Python Training in Chandigarh with most experienced professionals. Our Python Course in Chandigarh will cover each and every aspect of python which is necessary for you to know in order to become the most sought-after candidate for the companies.

    Student Review

    Python Training in Chandigarh
    Manpreet Kaur
    Web Designing Course in Chandigarh 5/5 stars

    I joined Python Training in Chandigarh which is Provided by CBitss Technologies. The best Thing – Their Training is based on Live Projects and Hands on Practical Knowledge.

    Python Training in Chandigarh

    Python Training in Chandigarh

    Rated PHP training in Chandigarh
    5/5 based on 13969 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

    Student Review

    Java Training in Chandigarh
    Ashutosh Kumar

    July 26, 2021

    5/5 stars

    I have done my Java Training in Chandigarh which is offered by CBitss Technologies and it is the best place to get training from basics to advanced level.

    Java Training in Chandigarh

    Java Training in Chandigarh

    Rated java Training in chandigarh5/5 based on 15933 reviews

    Student Review

    Cloud Computing Training in Chandigarh
    Robin Singh
    5/5 stars
    I completed Cloud Computing Training in Chandigarh. It does a great job of explaining the high-level concepts of Cloud to beginners like myself.

    Cloud Computing Training in Chandigarh

    Cloud Computing Training in Chandigarh

    Rated Cloud Computing Training in Chandigarh
    5/5 based on 16955 reviews

    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 !!