i
Understanding Requirement: Why Java
Why Java is important to the Internet
Java On Linux
First Java Program
Java Virtual Machine Architecture
Class Loading Process by Class Loaders
Role Of Just In Time Compiler
Execution Engine
Data Types
Variables
Arrays
Operators
Arithmetic Operations
Shifting Operators
Logical Operators
Control Statements
Object Oriented Paradigms
The Three OOP principles
Looping Statements
JAVA Class Fundamentals
Command Line Arguments
Static Initialize
Creating an Object
Instance Variable Hiding
Overriding and Overloading of methods
Understanding The Access Controls
Nested And Inner Classes
Dynamic Method Dispatching
Abstract Classes
Using Final To Prevent Overriding & Inheritance
Garbage Collection
Defining a package
Understanding Classpath
Access Protection
Importing packages
Defining and Implementing An Interface
Abstract classes vs Interfaces
Generics
Annotations
Varargs
Foreach
Fundamentals Of Exception Handling
Types Of Exceptions
Learning exception handling, try-catch, multiple catch clauses
Nested Try Statements
Throw, Throws and Finally
Custom Exceptions
Java Thread Model
Creating A Thread
Context Switching
Synchronization: Methods And Statements
Inter-thread Communication
In multi-threaded applications the situation where multiple threads try to access the same resources happens very often and it finally produces erroneous and unforeseen results. So we need to be sure that only one thread will access any resource at a given time. We can use for this some synchronization mechanism.
Java provides us the mechanism to synchronize method or the block inside the method. A synchronized block in Java can be done on some object. If we have few synchronized blocks on the same object we will have one thread executing inside them at a time.
Below is an example, where we synchronize the Sender object inside the run() method of the ThreadedSend class. Alternately to it, we can make the whole send() block as synchronized and it will produce the same result. In that case, we don’t have to synchronize the Message object inside the run() method in ThreadedSend class.
Let’s see the same example on the synchronized method:
One note is that we don’t need to synchronize whole method in some cases, so in this case synchronizing only small block of method will be preferable.
Don't miss out!