Androidberry logo Androidberry text logo
AndroidBerry Home
  • Learn Java
  • Java Programs
  • Interview Questions
  • Androidberry facebook
  • Androidberry twitter
  • Androidberry google plus

Java Tutorials


Basic Introduction

Decision Making

Looping

Classes and Objects

Inheritance

Interface

Packages

Exception Handling

Introduction of Errors
Java Exceptions
Java Try Block
Java Catch Block
Java Finally Block
Java Throw Keyword
Java Throws Keyword
Java Builtin Exceptions
User Defined Exceptions

Multithreading

Java Multithreading
Creating a Thread
Thread Life Cycle
Thread Exceptions
Thread Synchronization

Java Applets

What is Applet?
Java Applet vs Application
Creating a Applet
Displaying Applet on Webpage
Applet Lifecycle
Applet Tag
Passing Parameters to Applet
Setting Color to applet
Update and Repaint method
Using Fonts in Applet

Graphics Programming

More on Java

Java Programs
Java Keywords Dictionary
Java Interview Questions

Java Multithreading

Multitasking Multithreading in Java

Multitasking/Multithreading

Java multithreading is a form of multitasking. A multithreaded program contains two or more parts that can run concurrently.

Each part of the program is called as a thread and each thread defines a seperate path of execution.

Program is divides into several subtasks for performing their operation at a time.

Example: While working on a computer you can perform many tasks at a time like typing a letter with listening a online song.

Types of Multitasking

  1. Process based
  2. Thread based

1. Process based

Process : It is program under the execution. Process based have following properties

  • A process based multitasking allows the computer to run two or more programs at a time.
  • A program is a smallest unit of code that can be dispatched by the scheduler.
  • Process is heavyweight task, that requires their own address space.
  • Java uses the Process based multitasking environment to reduce drawbacks of Interprocess communication.

2. Thread based

Thread: It is smallest part of program for performing multitasking. Thread based have following properties

  • In this type single program can perform two or more task simultaneusly.
  • Process based system handles the whole program but, thread based handles by dividing the task into threads.
  • Thread share the same address space and cooperatively share the same heavy weight process.
  • Multithreading is multitasking in java.

Difference between Multithreading and Multiprocessing.

Multithreading vs Multiprocessing Difference
Sr.no Multithreading Multiprocessing
1. Multi-threading refers to an application with multiple threads running within a process. Multi-processing refers to an application organised across multiple OS-level processess.
2. Multi-threading means executing different parts of a program simultaneusly. Multi-processing means executing several programs at a time using more than one processor.
3. Same job can be broken logically and executed simultaneously and the results are combined at the end of processing. Several jobs can run at the same time.
4. The OS can allow hundreds of threads to be active, regardless of the number of processors. Multiprocessing means that we are using a computer that has multiple processors.
5. Multithreading is the ability to perform different tasks of a process simultaneusly. Multiprocessing have more than one processor.
6. Multithreading is achieved by using a separate thread for each task Multiprocessing is achieved by hadling each thread to each separate processor.
7. From several threads in a process, at a time cpu will handle only a single thread. It has concurrent processing system for performing all tasks at a time.
8. Multithreading is performed by switching between the tasks but,Not all at a time. Multiprocessing is performed by simultaneusly performing tasks without switching between processess.
9. Program is divided into different parts(threads) which shares the memory and processor time and will be executed simultanuesly. Processor allocates some memory for each program to be executed.Hence it has its own memory.

Advantages of multithreading

  1. Multithreading enables us to do multiple things at a time
  2. Large program can be divided into threads for executing parallely.
  3. The program speed is improved by dividing it into threads for concurret execution
  4. Threads are used in many java-enabled browsers.
<< Previous Next >>

See Also

All Java Programs
Java Keywords
Java Interview Questions

AndroidBerry Support

About us
Contact us
Suggest us
Questions?

Follow us

Androidberry FacebookFacebook
Androidberry TwitterTwitter
Androidberry GooglePlusGoogle+
Back to top
Androidberry Name Logo