Multithreading in Java : A Practical View

Table of Contents
    Add a header to begin generating the table of contents


    This article explains what threads are in Java. It elaborates on their uses and on how to implement multi-threading in Java.


    In a multitasking environment, having multiple threads helps the programmer to create efficient programs. In the context of Java, thread means two different things:

    Fig 1: Process

    An instance of java.lang.Thread


    A thread of execution


    An instance of a thread is just an object like any other object in Java. It has variables and methods, and lives and dies on the heap, but a thread of execution is an individual process (a lightweight process) that has its own stack. In Java, there is one thread per stack or vice versa. Even if you don’t create any thread in your program, there is a thread running in your program, by default, which is called the Main thread. The main() function of Java or the starting point of a Java program runs in the Main thread, or we can say that the Main thread controls the execution of the main() function of a Java program.

    Here is an article that appeared on Open Source For You (OSFY) February 2015 edition that does a deep dive into Multithreading in Java.



    Have a look into the article and let us know what you think.

    Share this material with your friend:

    Leave a Comment