- Java Programming Basics
- Java Tutorial
- Java Overview
- Java Environment Setup
- Java Program Structure
- Java Basic Syntax
- Java First Program
- Java Constants
- Java Separators
- Java Keywords
- Java Data Types
- Java Data Types
- Java Integers
- Java Floating Point
- Java Characters
- Java Booleans
- Java Numbers
- Java Programming Variables
- Java Variables
- Java Variable Types
- Java Variable Scope
- Java Type Conversion
- Java Type Casting
- Java Auto Type Promotion
- Java Type Promotion Rules
- Java Programming Arrays
- Java Arrays
- Java One Dimensional Array
- Java Multidimensional Array
- Java Programming Operators
- Java Operators
- Java Arithmetic Operators
- Java Increment Decrement
- Java Bitwise Operators
- Java Left Shift
- Java Right Shift
- Java Relational Operators
- Java Boolean Logical Operators
- Java Ternary(?) Operator
- Java Operator Precedence
- Java Control Statements
- Java Decision Making
- Java if if-else if-else-if
- Java switch Statement
- Java Loops
- Java while Loop
- Java do-while Loop
- Java for Loop
- Java for-each Loop
- Java Nested Loops
- Java break Statement
- Java continue Statement
- Java Class Object Method
- Java Classes and Objects
- Java Class
- Java Object
- Java new Operator
- Java Methods
- Java Constructors
- Java this Keyword
- Java Stack
- Java Overloading Recursion
- Java Method Overloading
- Java Constructor Overloading
- Java Object as Parameter
- Java Call by Value Reference
- Java Returning Objects
- Java Recursion
- Java Modifier Types
- Java Encapsulate Poly String
- Java Encapsulation
- Java Polymorphism
- Java Nested Inner Class
- Java Strings
- Java Command Line Arguments
- Java Variable Length Arguments
- Java Inheritance Abstraction
- Java Inheritance
- Java super Superclass
- Java Multilevel Hierarchy
- Java Method Overriding
- Java Abstraction
- Java Packages Interfaces
- Java Packages
- Java Access Protection
- Java Import Statement
- Java Interfaces
- Java Programming Exceptions
- Java Exception Handling
- Java try catch
- Java throw throws
- Java finally Block
- Java Built In Exceptions
- Java Exception Subclasses
- Java Chained Exceptions
- Java Multithreading
- Java Multithreading
- Java Thread Model
- Java Main Thread
- Java Create Thread
- Java Thread Priorities
- Java Synchronization
- Java Inter Thread Communication
- Java Suspend Resume Stop Thread
- Java Get Thread State
- Java Enum Autobox Annotation
- Java Enumerations
- Java Type Wrappers
- Java Autoboxing
- Java Annotation
- Java Marker Annotations
- Java Single Member Annotation
- Java Built In Annotations
- Java Type Annotations
- Java Repeating Annotations
- Java Data File Handling
- Java Files I/O
- Java Streams
- Java Read Console Input
- Java Write Console Output
- Java PrintWriter Class
- Java Read Write Files
- Java Automatically Close File
- Java Programming Advance
- Java Date and Time
- Java Regular Expressions
- Java Collections Framework
- Java Generics
- Java Data Structures
- Java Network Programming
- Java Serialization
- Java Send Email
- Java Applet Basics
- Java Documentation
- Java Programming Examples
- Java Programming Examples
Java Multithreading
Java offers built-in support for the multithreaded programming. A multithreaded programs contains two or more parts that can run at the same time. Each part of such a program is called a thread, and each thread defines a separate path of execution. Therefore, multithreading is a special form of multitasking.
You are almost certainly acquainted with multitasking because it is supported by virtually every modern operating systems. However, there are two distinct types of multitasking given here:
- process-based multitasking
- thread-based multitasking
It is important to understand about the difference between the above two.
Process-Based Multitasking
For many readers, process-based multitasking is more companion form. A process is, a program that is executing. Therefore, a process-based multitasking is the feature which allows your computer to run two or more programs at the same time. For instance, process-based multitasking allows you to run the Java compiler concurrently which you are using a text editor or visiting a website. In the process-based multitasking, a program is the smallest building block of code which can be dispatched by the scheduler.
Thread-Based Multitasking
In thread-based multitasking environment, the thread is the smallest unit of dispatchable code. It means that a thread-based multitasking program can execute two or more tasks at the same time. For instance, a text editor can format the text concurrently that it is printing, as long as these two actions are being executed by the two separate threads. Therefore, the process-based multitasking handles with the "big picture", and the thread-based multitasking handles the details.
Multithreading
Multithreading provides you to write efficient programs that makes maximum use of the processing power available in the system. One crucial way multithreading achieves this is by keeping the idle time to a minimum. This is especially crucial for the interactive, networked environment in which Java operates because idle time is common. For example, the transmission rate of the data over a network is much slower than the rate at which the computer can process it. Yet the local file system resources are read and written at a much slower pace than they can be processed by the CPU. And user input is much slower than the computer. In a single-threaded environment, your program has to wait for each of these tasks to end before it can proceed to the next one, even though most of the time the program is idle, waiting for the input. Multithreading allows you to reduce this idle time because another thread can run when one is waiting.
If you have already programmed for operating systems such as Windows, then you are already familiar with multithreaded programming. Nevertheless, the fact that Java manages threads makes multithreading especially convenient because many of the details are handled for you.
« Previous Tutorial Next Tutorial »