Session 7_MULTITHREADING in java example.pptTabassumMaktum
This document discusses multithreading in Java. It begins by introducing multitasking and how computers can appear to work on multiple tasks concurrently through fast task switching by the operating system scheduler. It then discusses how multitasking can be implemented through either process-based or thread-based approaches. The rest of the document focuses on thread-based multitasking in Java, including the Java thread model, thread life cycle states, ways to create threads by extending the Thread class or implementing Runnable, and common thread methods like start(), run(), join(), yield(), sleep(), and stop().
Session 7_MULTITHREADING in java example.pptTabassumMaktum
This document discusses multithreading in Java. It begins by introducing multitasking and how computers can appear to work on multiple tasks concurrently through fast task switching by the operating system scheduler. It then discusses how multitasking can be implemented through either process-based or thread-based approaches. The rest of the document focuses on thread-based multitasking in Java, including the Java thread model, thread life cycle states, ways to create threads by extending the Thread class or implementing Runnable, and common thread methods like start(), run(), join(), yield(), sleep(), and stop().
- The document discusses multithreading concepts in Java like thread life cycle, creating threads, thread synchronization, and inter-thread communication.
- It explains that threads are lightweight subprocesses that share memory space for better efficiency compared to processes. Threads can run concurrently to achieve multitasking.
- The key methods for working with threads are discussed including start(), sleep(), join(), getName(), setName() and currentThread().
The document discusses threads in Java. It defines a thread as an individual unit of execution within a process. Threads allow multiple tasks to run concurrently within the same process. The document provides examples of using threads for different tasks in a video game. It also describes the four states a thread can be in and common thread methods like start(), sleep(), join(), etc. Finally, it shows examples of creating thread classes that extend Thread and implement Runnable.
1. The document discusses threads and multithreading in Java. It defines threads as independent paths of execution within a process and explains how Java supports multithreading.
2. Key concepts covered include the different states a thread can be in (new, ready, running, blocked, dead), thread priorities, synchronization to allow threads to safely access shared resources, and methods to control threads like start(), sleep(), join(), etc.
3. Examples are provided to demonstrate how to create and manage multiple threads that run concurrently and synchronize access to shared resources.
java notes, object oriented programming using java, java tutorial, lecture notes, java programming notes, java example programs, java programs with explanation, java source code with output, java programs, java coding, java codes, java slides, java notes,multithreading in java, java multithreading notes, java multithreading notes,different types of multithreading in Java,multithreading with an example, multithreading in Java
Threads : Single and Multitasking, Creating and terminating the thread, Single and Multi tasking
using threads, Deadlock of threads, Thread communication.
The document discusses multithreading and threading concepts in Java. It defines a thread as a single sequential flow of execution within a program. Multithreading allows executing multiple threads simultaneously by sharing the resources of a process. The key benefits of multithreading include proper utilization of resources, decreased maintenance costs, and improved performance of complex applications. Threads have various states like new, runnable, running, blocked, and dead during their lifecycle. The document also explains different threading methods like start(), run(), sleep(), yield(), join(), wait(), notify() etc and synchronization techniques in multithreading.
Session 7_MULTITHREADING in java example.pptTabassumMaktum
This document discusses multithreading in Java. It begins by introducing multitasking and how computers can appear to work on multiple tasks concurrently through fast task switching by the operating system scheduler. It then discusses how multitasking can be implemented through either process-based or thread-based approaches. The rest of the document focuses on thread-based multitasking in Java, including the Java thread model, thread life cycle states, ways to create threads by extending the Thread class or implementing Runnable, and common thread methods like start(), run(), join(), yield(), sleep(), and stop().
Session 7_MULTITHREADING in java example.pptTabassumMaktum
This document discusses multithreading in Java. It begins by introducing multitasking and how computers can appear to work on multiple tasks concurrently through fast task switching by the operating system scheduler. It then discusses how multitasking can be implemented through either process-based or thread-based approaches. The rest of the document focuses on thread-based multitasking in Java, including the Java thread model, thread life cycle states, ways to create threads by extending the Thread class or implementing Runnable, and common thread methods like start(), run(), join(), yield(), sleep(), and stop().
- The document discusses multithreading concepts in Java like thread life cycle, creating threads, thread synchronization, and inter-thread communication.
- It explains that threads are lightweight subprocesses that share memory space for better efficiency compared to processes. Threads can run concurrently to achieve multitasking.
- The key methods for working with threads are discussed including start(), sleep(), join(), getName(), setName() and currentThread().
The document discusses threads in Java. It defines a thread as an individual unit of execution within a process. Threads allow multiple tasks to run concurrently within the same process. The document provides examples of using threads for different tasks in a video game. It also describes the four states a thread can be in and common thread methods like start(), sleep(), join(), etc. Finally, it shows examples of creating thread classes that extend Thread and implement Runnable.
1. The document discusses threads and multithreading in Java. It defines threads as independent paths of execution within a process and explains how Java supports multithreading.
2. Key concepts covered include the different states a thread can be in (new, ready, running, blocked, dead), thread priorities, synchronization to allow threads to safely access shared resources, and methods to control threads like start(), sleep(), join(), etc.
3. Examples are provided to demonstrate how to create and manage multiple threads that run concurrently and synchronize access to shared resources.
java notes, object oriented programming using java, java tutorial, lecture notes, java programming notes, java example programs, java programs with explanation, java source code with output, java programs, java coding, java codes, java slides, java notes,multithreading in java, java multithreading notes, java multithreading notes,different types of multithreading in Java,multithreading with an example, multithreading in Java
Threads : Single and Multitasking, Creating and terminating the thread, Single and Multi tasking
using threads, Deadlock of threads, Thread communication.
The document discusses multithreading and threading concepts in Java. It defines a thread as a single sequential flow of execution within a program. Multithreading allows executing multiple threads simultaneously by sharing the resources of a process. The key benefits of multithreading include proper utilization of resources, decreased maintenance costs, and improved performance of complex applications. Threads have various states like new, runnable, running, blocked, and dead during their lifecycle. The document also explains different threading methods like start(), run(), sleep(), yield(), join(), wait(), notify() etc and synchronization techniques in multithreading.
This document discusses multi-threaded programming in Java. It covers key concepts like synchronized blocks, static synchronization, deadlocks, inter-thread communication, thread states (new, runnable, running, non-runnable, terminated), creating threads by extending Thread class and implementing Runnable interface, starting threads using start() vs calling run() directly, joining threads, naming threads, setting thread priority, and using methods like sleep(), yield(), currentThread() etc. It provides examples to explain these concepts.
This document discusses multithreading in Java. It defines two types of multitasking: process-based and thread-based. Process-based multitasking allows multiple programs to run concurrently, while thread-based multitasking allows a single program to perform multiple tasks simultaneously by dividing the program into threads. The document describes how to create threads by implementing the Runnable interface or extending the Thread class, and how threads can be scheduled using priorities.
The document discusses threads and threading in Java. It covers:
- Threads allow multitasking by running multiple threads concurrently within a program.
- Threads can be created by extending the Thread class or implementing the Runnable interface.
- Threads have different states like new, ready, running, blocked, and dead. Methods like start(), sleep(), join(), yield(), etc. change a thread's state.
- Synchronization is needed to prevent data corruption when multiple threads access shared resources concurrently.
This document provides an introduction to multithreading in Java. It discusses that a thread is similar to a program with a single flow of control and Java supports executing multiple threads concurrently through multithreading. It describes the different states a thread passes through during its lifetime, including newborn, runnable, running, blocked, and dead. It also explains how to create threads in Java by extending the Thread class or implementing the Runnable interface and calling the start() method. Finally, it discusses synchronization which is used to prevent threads from concurrently accessing shared resources and introduces race conditions.
This document provides information about Java threads through a series of slides. It defines a thread as a single sequential flow of control within a program. It discusses how to define and launch threads by extending the Thread class or implementing the Runnable interface. It outlines the life cycle of a thread and its possible states such as new, runnable, blocked, waiting and terminated. It also covers how to interrupt threads and related methods.
This document discusses Java threads and synchronization. It begins with an introduction to threads, defining a thread as a single sequential flow of control within a program. It then covers how to define and launch threads in Java by extending the Thread class or implementing the Runnable interface. The life cycle of a Java thread is explained, including the various thread states. Methods for interrupting threads and thread synchronization using synchronized methods and statements are discussed. Finally, Java's monitor model for thread synchronization is described.
1) The document discusses various topics related to Java multithreading including introduction to threads, creation and life cycle of threads, stopping and blocking threads, using thread methods, thread priority, thread synchronization, and inter-thread communication.
2) It provides examples of creating threads by extending the Thread class and implementing the Runnable interface. Methods like start(), run(), sleep(), setPriority(), getPriority() are discussed.
3) Synchronization techniques like synchronized keyword and wait-notify methods are explained with examples to achieve inter-thread communication and coordination.
Thread is the basic unit of CPU utilization in an operating system. A single-threaded process can only perform one task at a time, while a multithreaded process can perform multiple tasks simultaneously using threads. Java uses the Thread class and Runnable interface to create and manage threads. The main thread is created automatically, while additional threads can be instantiated by implementing Runnable or extending Thread. Synchronization is needed when threads share resources to prevent race conditions.
Multithreading allows a program to split into multiple subprograms called threads that can run concurrently. Threads go through various states like new, runnable, running, blocked, and dead. There are two main ways to create threads: by extending the Thread class or implementing the Runnable interface. Threads can have different priorities that influence scheduling order. Multithreading allows performing multiple operations simultaneously to save time without blocking the user, and exceptions in one thread do not affect others.
This document provides an overview of threads in Java. It discusses what threads are, the different states threads can be in, how to set thread priorities, and the Thread class. It also covers the two main ways to create Java threads: by extending the Thread class or implementing the Runnable interface. Additional topics covered include thread groups, synchronization to avoid race conditions, and inter-thread communication.
This document provides information on multithreading, networking, and other Java concepts. It discusses how to create threads in Java by extending the Thread class or implementing Runnable, and describes methods like sleep(), wait(), notify() etc. It also covers networking topics like sockets, servers, clients and protocols. Examples of socket programming and a chatting program using sockets are included. Finally, it discusses classes like URL, URLConnection and HttpURLConnection for working with URLs.
This presentation will give a brief idea about threads.
This presentation gives you what is required if you are a starter.
This has the lifecycle, multithreading and differences between multithreadind and normal threading.
This presentation even have example programs.
Threads allow multiple tasks to run concurrently within a single process. Each thread has its own call stack and shares resources like memory with other threads in the same process. There are two main ways to implement threads in Java - by extending the Thread class or implementing the Runnable interface. Synchronization is needed when multiple threads access shared resources to prevent data corruption. Common methods like start(), join(), sleep() and priority help control thread execution and behavior.
Multithreading in Java Object Oriented Programming languagearnavytstudio2814
Multithreading in Java allows executing multiple threads simultaneously. A thread is the smallest unit of processing and is lightweight. Threads share memory space, which saves memory compared to processes that have separate memory areas. Context switching between threads is also faster than between processes. Common uses of multithreading include games, animations, and performing multiple operations simultaneously to save time while individual threads remain independent and unaffected by exceptions in other threads.
The document discusses multithreaded programming in Java. It describes that a multithreaded program contains two or more parts that can run concurrently as separate execution paths called threads. Threads are lighter weight than processes and allow for more efficient CPU usage by enabling idle time to be minimized. The Java threading model eliminates the single event loop of single-threaded programs by allowing threads to run independently such that if one thread blocks, other threads can continue running. Threads can be created by implementing the Runnable interface or extending the Thread class.
This document discusses multithreading and generic programming in Java. It covers thread concepts like thread life cycle, creating threads by extending Thread class and implementing Runnable interface. It provides examples of multithreading in applications. Generic programming concepts like generic classes and methods are also briefly introduced. The key outcomes are to develop Java applications using threads and generics.
The document discusses threads and multithreading in Java. It defines a thread as a flow of execution with a beginning, execution sequence, and end. Multithreading allows multiple threads to run simultaneously within a single program. It describes how to create threads by extending the Thread class or implementing Runnable. The document also discusses thread states, priorities, synchronization, and race conditions that can occur when multiple threads access shared data.
Advanced control scheme of doubly fed induction generator for wind turbine us...IJECEIAES
This paper describes a speed control device for generating electrical energy on an electricity network based on the doubly fed induction generator (DFIG) used for wind power conversion systems. At first, a double-fed induction generator model was constructed. A control law is formulated to govern the flow of energy between the stator of a DFIG and the energy network using three types of controllers: proportional integral (PI), sliding mode controller (SMC) and second order sliding mode controller (SOSMC). Their different results in terms of power reference tracking, reaction to unexpected speed fluctuations, sensitivity to perturbations, and resilience against machine parameter alterations are compared. MATLAB/Simulink was used to conduct the simulations for the preceding study. Multiple simulations have shown very satisfying results, and the investigations demonstrate the efficacy and power-enhancing capabilities of the suggested control system.
This document discusses multi-threaded programming in Java. It covers key concepts like synchronized blocks, static synchronization, deadlocks, inter-thread communication, thread states (new, runnable, running, non-runnable, terminated), creating threads by extending Thread class and implementing Runnable interface, starting threads using start() vs calling run() directly, joining threads, naming threads, setting thread priority, and using methods like sleep(), yield(), currentThread() etc. It provides examples to explain these concepts.
This document discusses multithreading in Java. It defines two types of multitasking: process-based and thread-based. Process-based multitasking allows multiple programs to run concurrently, while thread-based multitasking allows a single program to perform multiple tasks simultaneously by dividing the program into threads. The document describes how to create threads by implementing the Runnable interface or extending the Thread class, and how threads can be scheduled using priorities.
The document discusses threads and threading in Java. It covers:
- Threads allow multitasking by running multiple threads concurrently within a program.
- Threads can be created by extending the Thread class or implementing the Runnable interface.
- Threads have different states like new, ready, running, blocked, and dead. Methods like start(), sleep(), join(), yield(), etc. change a thread's state.
- Synchronization is needed to prevent data corruption when multiple threads access shared resources concurrently.
This document provides an introduction to multithreading in Java. It discusses that a thread is similar to a program with a single flow of control and Java supports executing multiple threads concurrently through multithreading. It describes the different states a thread passes through during its lifetime, including newborn, runnable, running, blocked, and dead. It also explains how to create threads in Java by extending the Thread class or implementing the Runnable interface and calling the start() method. Finally, it discusses synchronization which is used to prevent threads from concurrently accessing shared resources and introduces race conditions.
This document provides information about Java threads through a series of slides. It defines a thread as a single sequential flow of control within a program. It discusses how to define and launch threads by extending the Thread class or implementing the Runnable interface. It outlines the life cycle of a thread and its possible states such as new, runnable, blocked, waiting and terminated. It also covers how to interrupt threads and related methods.
This document discusses Java threads and synchronization. It begins with an introduction to threads, defining a thread as a single sequential flow of control within a program. It then covers how to define and launch threads in Java by extending the Thread class or implementing the Runnable interface. The life cycle of a Java thread is explained, including the various thread states. Methods for interrupting threads and thread synchronization using synchronized methods and statements are discussed. Finally, Java's monitor model for thread synchronization is described.
1) The document discusses various topics related to Java multithreading including introduction to threads, creation and life cycle of threads, stopping and blocking threads, using thread methods, thread priority, thread synchronization, and inter-thread communication.
2) It provides examples of creating threads by extending the Thread class and implementing the Runnable interface. Methods like start(), run(), sleep(), setPriority(), getPriority() are discussed.
3) Synchronization techniques like synchronized keyword and wait-notify methods are explained with examples to achieve inter-thread communication and coordination.
Thread is the basic unit of CPU utilization in an operating system. A single-threaded process can only perform one task at a time, while a multithreaded process can perform multiple tasks simultaneously using threads. Java uses the Thread class and Runnable interface to create and manage threads. The main thread is created automatically, while additional threads can be instantiated by implementing Runnable or extending Thread. Synchronization is needed when threads share resources to prevent race conditions.
Multithreading allows a program to split into multiple subprograms called threads that can run concurrently. Threads go through various states like new, runnable, running, blocked, and dead. There are two main ways to create threads: by extending the Thread class or implementing the Runnable interface. Threads can have different priorities that influence scheduling order. Multithreading allows performing multiple operations simultaneously to save time without blocking the user, and exceptions in one thread do not affect others.
This document provides an overview of threads in Java. It discusses what threads are, the different states threads can be in, how to set thread priorities, and the Thread class. It also covers the two main ways to create Java threads: by extending the Thread class or implementing the Runnable interface. Additional topics covered include thread groups, synchronization to avoid race conditions, and inter-thread communication.
This document provides information on multithreading, networking, and other Java concepts. It discusses how to create threads in Java by extending the Thread class or implementing Runnable, and describes methods like sleep(), wait(), notify() etc. It also covers networking topics like sockets, servers, clients and protocols. Examples of socket programming and a chatting program using sockets are included. Finally, it discusses classes like URL, URLConnection and HttpURLConnection for working with URLs.
This presentation will give a brief idea about threads.
This presentation gives you what is required if you are a starter.
This has the lifecycle, multithreading and differences between multithreadind and normal threading.
This presentation even have example programs.
Threads allow multiple tasks to run concurrently within a single process. Each thread has its own call stack and shares resources like memory with other threads in the same process. There are two main ways to implement threads in Java - by extending the Thread class or implementing the Runnable interface. Synchronization is needed when multiple threads access shared resources to prevent data corruption. Common methods like start(), join(), sleep() and priority help control thread execution and behavior.
Multithreading in Java Object Oriented Programming languagearnavytstudio2814
Multithreading in Java allows executing multiple threads simultaneously. A thread is the smallest unit of processing and is lightweight. Threads share memory space, which saves memory compared to processes that have separate memory areas. Context switching between threads is also faster than between processes. Common uses of multithreading include games, animations, and performing multiple operations simultaneously to save time while individual threads remain independent and unaffected by exceptions in other threads.
The document discusses multithreaded programming in Java. It describes that a multithreaded program contains two or more parts that can run concurrently as separate execution paths called threads. Threads are lighter weight than processes and allow for more efficient CPU usage by enabling idle time to be minimized. The Java threading model eliminates the single event loop of single-threaded programs by allowing threads to run independently such that if one thread blocks, other threads can continue running. Threads can be created by implementing the Runnable interface or extending the Thread class.
This document discusses multithreading and generic programming in Java. It covers thread concepts like thread life cycle, creating threads by extending Thread class and implementing Runnable interface. It provides examples of multithreading in applications. Generic programming concepts like generic classes and methods are also briefly introduced. The key outcomes are to develop Java applications using threads and generics.
The document discusses threads and multithreading in Java. It defines a thread as a flow of execution with a beginning, execution sequence, and end. Multithreading allows multiple threads to run simultaneously within a single program. It describes how to create threads by extending the Thread class or implementing Runnable. The document also discusses thread states, priorities, synchronization, and race conditions that can occur when multiple threads access shared data.
Advanced control scheme of doubly fed induction generator for wind turbine us...IJECEIAES
This paper describes a speed control device for generating electrical energy on an electricity network based on the doubly fed induction generator (DFIG) used for wind power conversion systems. At first, a double-fed induction generator model was constructed. A control law is formulated to govern the flow of energy between the stator of a DFIG and the energy network using three types of controllers: proportional integral (PI), sliding mode controller (SMC) and second order sliding mode controller (SOSMC). Their different results in terms of power reference tracking, reaction to unexpected speed fluctuations, sensitivity to perturbations, and resilience against machine parameter alterations are compared. MATLAB/Simulink was used to conduct the simulations for the preceding study. Multiple simulations have shown very satisfying results, and the investigations demonstrate the efficacy and power-enhancing capabilities of the suggested control system.
Using recycled concrete aggregates (RCA) for pavements is crucial to achieving sustainability. Implementing RCA for new pavement can minimize carbon footprint, conserve natural resources, reduce harmful emissions, and lower life cycle costs. Compared to natural aggregate (NA), RCA pavement has fewer comprehensive studies and sustainability assessments.
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...IJECEIAES
Medical image analysis has witnessed significant advancements with deep learning techniques. In the domain of brain tumor segmentation, the ability to
precisely delineate tumor boundaries from magnetic resonance imaging (MRI)
scans holds profound implications for diagnosis. This study presents an ensemble convolutional neural network (CNN) with transfer learning, integrating
the state-of-the-art Deeplabv3+ architecture with the ResNet18 backbone. The
model is rigorously trained and evaluated, exhibiting remarkable performance
metrics, including an impressive global accuracy of 99.286%, a high-class accuracy of 82.191%, a mean intersection over union (IoU) of 79.900%, a weighted
IoU of 98.620%, and a Boundary F1 (BF) score of 83.303%. Notably, a detailed comparative analysis with existing methods showcases the superiority of
our proposed model. These findings underscore the model’s competence in precise brain tumor localization, underscoring its potential to revolutionize medical
image analysis and enhance healthcare outcomes. This research paves the way
for future exploration and optimization of advanced CNN models in medical
imaging, emphasizing addressing false positives and resource efficiency.
Embedded machine learning-based road conditions and driving behavior monitoringIJECEIAES
Car accident rates have increased in recent years, resulting in losses in human lives, properties, and other financial costs. An embedded machine learning-based system is developed to address this critical issue. The system can monitor road conditions, detect driving patterns, and identify aggressive driving behaviors. The system is based on neural networks trained on a comprehensive dataset of driving events, driving styles, and road conditions. The system effectively detects potential risks and helps mitigate the frequency and impact of accidents. The primary goal is to ensure the safety of drivers and vehicles. Collecting data involved gathering information on three key road events: normal street and normal drive, speed bumps, circular yellow speed bumps, and three aggressive driving actions: sudden start, sudden stop, and sudden entry. The gathered data is processed and analyzed using a machine learning system designed for limited power and memory devices. The developed system resulted in 91.9% accuracy, 93.6% precision, and 92% recall. The achieved inference time on an Arduino Nano 33 BLE Sense with a 32-bit CPU running at 64 MHz is 34 ms and requires 2.6 kB peak RAM and 139.9 kB program flash memory, making it suitable for resource-constrained embedded systems.
ACEP Magazine edition 4th launched on 05.06.2024Rahul
This document provides information about the third edition of the magazine "Sthapatya" published by the Association of Civil Engineers (Practicing) Aurangabad. It includes messages from current and past presidents of ACEP, memories and photos from past ACEP events, information on life time achievement awards given by ACEP, and a technical article on concrete maintenance, repairs and strengthening. The document highlights activities of ACEP and provides a technical educational article for members.
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEMHODECEDSIET
Time Division Multiplexing (TDM) is a method of transmitting multiple signals over a single communication channel by dividing the signal into many segments, each having a very short duration of time. These time slots are then allocated to different data streams, allowing multiple signals to share the same transmission medium efficiently. TDM is widely used in telecommunications and data communication systems.
### How TDM Works
1. **Time Slots Allocation**: The core principle of TDM is to assign distinct time slots to each signal. During each time slot, the respective signal is transmitted, and then the process repeats cyclically. For example, if there are four signals to be transmitted, the TDM cycle will divide time into four slots, each assigned to one signal.
2. **Synchronization**: Synchronization is crucial in TDM systems to ensure that the signals are correctly aligned with their respective time slots. Both the transmitter and receiver must be synchronized to avoid any overlap or loss of data. This synchronization is typically maintained by a clock signal that ensures time slots are accurately aligned.
3. **Frame Structure**: TDM data is organized into frames, where each frame consists of a set of time slots. Each frame is repeated at regular intervals, ensuring continuous transmission of data streams. The frame structure helps in managing the data streams and maintaining the synchronization between the transmitter and receiver.
4. **Multiplexer and Demultiplexer**: At the transmitting end, a multiplexer combines multiple input signals into a single composite signal by assigning each signal to a specific time slot. At the receiving end, a demultiplexer separates the composite signal back into individual signals based on their respective time slots.
### Types of TDM
1. **Synchronous TDM**: In synchronous TDM, time slots are pre-assigned to each signal, regardless of whether the signal has data to transmit or not. This can lead to inefficiencies if some time slots remain empty due to the absence of data.
2. **Asynchronous TDM (or Statistical TDM)**: Asynchronous TDM addresses the inefficiencies of synchronous TDM by allocating time slots dynamically based on the presence of data. Time slots are assigned only when there is data to transmit, which optimizes the use of the communication channel.
### Applications of TDM
- **Telecommunications**: TDM is extensively used in telecommunication systems, such as in T1 and E1 lines, where multiple telephone calls are transmitted over a single line by assigning each call to a specific time slot.
- **Digital Audio and Video Broadcasting**: TDM is used in broadcasting systems to transmit multiple audio or video streams over a single channel, ensuring efficient use of bandwidth.
- **Computer Networks**: TDM is used in network protocols and systems to manage the transmission of data from multiple sources over a single network medium.
### Advantages of TDM
- **Efficient Use of Bandwidth**: TDM all
Using recycled concrete aggregates (RCA) for pavements is crucial to achieving sustainability. Implementing RCA for new pavement can minimize carbon footprint, conserve natural resources, reduce harmful emissions, and lower life cycle costs. Compared to natural aggregate (NA), RCA pavement has fewer comprehensive studies and sustainability assessments.
3. 3
Multithreading
Java provides built in support for multithreaded programming.
A Multithreaded program contains two or more parts that can run concurrently.
Each part of such a program is called a Thread.
Each thread defines a separate path of execution.
Multithreading is a specialized form of Multitasking.
Multitasking is divided into two types:
Process-based: Here two or more programs runs concurrently. You can run Windows
calculator and a Text editor (Notepad) at the same time.
Thread-based: A single program can perform two or more tasks simultaneously. For
example, text editor can print while formatting is being done.
Multithreading enables you to write very efficient programs that make maximum use of
CPU, because idle time can be kept to minimum. This is especially important for the
interactive networked application because idle time is common. In a traditional single
threaded environment, your program has to wait for each of the tasks to finish before it can
proceed to the next one. This will result in idle time. Multithreading lets you gain access to
this idle time and put it to good use.
:: Introduction
4. 4
Multithreading
One thread can pause without stopping other parts of your Program. Multithreading allows
animation loops to sleep for a second between each frame without causing the whole
system to pause. When a thread blocks in a java program, only the single thread that is
blocked pauses. All other threads continue to run.
Also note the following points regarding threads.
1. A thread can be running. It can be ready to run as soon as it begins execution
2. A running thread can be suspended which temporarily suspends its activity
3. A suspended thread can be resumed
4. A thread can be blocked when waiting for a resource. (sleeps for a while)
At any time a thread can be terminated, which means the thread stops. Once stopped it
cannot be resumed.
:: Java’s Thread Model
5. 5
New born
Running
start( )
Multithreading
:: Thread Life Cycle
Blocked
Dead
Runnable
stop( )
stop( )
stop( )
suspend( )
sleep( )
wait( )
resume( )
notify( )
New Thread
Active
Thread
Idle Thread
(Not Runnable)
yield( )
Killed
Thread
Fig:- State Transition diagram of a thread
6. 6
Multithreading
You can create a thread in one of the following ways:-
1. Extending Thread: The first way to create a thread is to create a new class that
extends the Thread class and then to create an instance of this class. This class must
override the run() method which is the entry point for the new thread.
2. Implementing Runnable Interface: The easiest way to create a thread is to create a
class that implements the Runnable interface. To implement Runnable, a class need only
implement a single method called run(). The Format of that function is public void run().
Either of these two approaches may be used. Since multiple inheritance doesn't allow us to
extend more than one class at a time, implementing the Runnable interface may help us in
this situation.
:: Creation of a thread
7. 7
Creating Threads
Threads are implemented as objects that contains a method
called run()
class MyThread extends Thread
{
public void run()
{
// thread body of execution
}
}
Create a thread:
MyThread thr1 = new MyThread();
Start Execution of threads:
thr1.start();
Create and Execute:
new MyThread().start();
:: Extending the thread class
8. 8
Creating Threads
:: Extending the thread class : example
class MyThread extends Thread { // the thread
public void run() {
System.out.println(" this thread is running ... ");
}
} // end class MyThread
class ThreadEx1 { // a program that utilizes the thread
public static void main(String [] args ) {
MyThread t = new MyThread();
// due to extending the Thread class (above)
// I can call start(), and this will call
// run(). start() is a method in class Thread.
t.start();
} // end main()
} // end class ThreadEx1
9. 9
Creating Threads
class MyThread implements Runnable
{
.....
public void run()
{
// thread body of execution
}
}
Creating Object:
MyThread myObject = new MyThread();
Creating Thread Object:
Thread thr1 = new Thread( myObject );
Start Execution:
thr1.start();
:: Implementing the runnable interface
10. 10
Creating Threads
:: Implementing the runnable interface : example
class MyThread implements Runnable {
public void run() {
System.out.println(" this thread is running ... ");
}
} // end class MyThread
class ThreadEx2 {
public static void main(String [] args ) {
Thread t = new Thread(new MyThread());
// due to implementing the Runnable interface
// I can call start(), and this will call run().
t.start();
} // end main()
} // end class ThreadEx2
11. 11
class A extends Thread
{
public void run()
{
for(int i=1;i<=5;i++)
{
System.out.println("t From ThreadA: i= "+i);
}
System.out.println("Exit from A");
}
}
class B extends Thread
{
public void run()
{
for(int j=1;j<=5;j++)
{
System.out.println("t From ThreadB: j= "+j);
}
System.out.println("Exit from B");
}
Creating Threads
:: Three threads example
12. 12
class C extends Thread
{
public void run()
{
for(int k=1;k<=5;k++)
{
System.out.println("t From ThreadC: k= "+k);
}
System.out.println("Exit from C");
}
}
class ThreadTest
{
public static void main(String args[])
{
new A().start();
new B().start();
new C().start();
}
}
Creating Threads
:: Three threads example
13. 13
java ThreadTest
From ThreadA: i= 1
From ThreadA: i= 2
From ThreadA: i= 3
From ThreadA: i= 4
From ThreadA: i= 5
Exit from A
From ThreadC: k= 1
From ThreadC: k= 2
From ThreadC: k= 3
From ThreadC: k= 4
From ThreadC: k= 5
Exit from C
From ThreadB: j= 1
From ThreadB: j= 2
From ThreadB: j= 3
From ThreadB: j= 4
From ThreadB: j= 5
Exit from B
Creating Threads
:: Three threads example: Run 1
14. 14
java ThreadTest
From ThreadA: i= 1
From ThreadA: i= 2
From ThreadA: i= 3
From ThreadA: i= 4
From ThreadA: i= 5
From ThreadC: k= 1
From ThreadC: k= 2
From ThreadC: k= 3
From ThreadC: k= 4
From ThreadC: k= 5
Exit from C
From ThreadB: j= 1
From ThreadB: j= 2
From ThreadB: j= 3
From ThreadB: j= 4
From ThreadB: j= 5
Exit from B
Exit from A
Creating Threads
:: Three threads example: Run 2
15. 15
Multithreading
start() Starts execution of the thread.
stop() Terminates the current thread.
suspend() Suspends the thread.
resume() Restarts the suspended thread.
sleep() This method suspends execution of the executing thread for the specified number of milliseconds. It
can throw an interrupted Exception.
getName() Obtains a thread name.
getPriority() Obtain a thread’s priority.
Isalive() Determine if a thread is still running.
wait() Waits for a thread to terminate.
run() Entry point for the Thread.
:: Thread class methods
16. 16
The thread is created when an object derived from the Thread class
is created
At this point, the thread is not executable — Java calls this the new
state
Once the start method has been called, the thread becomes
eligible for execution by the scheduler
If the thread calls the wait method in an Object, or calls the join
method in another thread object, the thread becomes blocked and
no longer eligible for execution
It becomes executable as a result of an associated notify method
being called by another thread, or if the thread with which it has
requested a join, becomes dead
Multithreading
:: Thread states
17. 17
A thread enters the dead state, either as a result of the
run method exiting (normally or as a result of an
unhandled exception) or because its destroy method has
been called
In the latter case, the thread is abruptly move to the
dead state and does not have the opportunity to execute
any finally clauses associated with its execution; it may
leave other objects locked
Multithreading
:: Thread states
18. 18
class A extends Thread
{
public void run()
{
for(int i=1;i<=5;i++)
{
if(1==1) yield();
System.out.println("t From ThreadA: i= "+i);
}
System.out.println("Exit from A");
}
}
class B extends Thread
{
public void run()
{
for(int j=1;j<=5;j++)
{
System.out.println("t From ThreadB: j= "+j);
if(j==2) stop();
}
System.out.println("Exit from B");
}
Using different methods of Thread class
19. 19
class C extends Thread
{
public void run()
{
for(int k=1;k<=5;k++)
{
System.out.println("t From ThreadC: k= "+k);
if(k==2)
try
{
sleep(1000);
}
catch(Exception e)
{ }
}
System.out.println("Exit from C");
}
}
class ThreadMethod
{
public static void main(String args[])
{
new A().start();
new B().start();
new C().start();
}
}
20. 20
Multithreading
Thread priorities are integers that specify the relative priority of one
thread to another.
Higher priority thread doesn't run any faster than a lower priority thread.
Instead a thread’s priority is used to decide when to switch from one
running thread to the next This is called as context switch.
A thread can have a maximum priority of 10 and a minimum of 1. Normal
Priority is 5.
:: Thread priorities
21. 21
In Java, each thread is assigned priority, which affects
the order in which it is scheduled for running. The
threads so far had same default priority
(NORM_PRIORITY) and they are served using FCFS
policy.
Java allows users to change priority:
ThreadName.setPriority(intNumber)
MIN_PRIORITY = 1
NORM_PRIORITY=5
MAX_PRIORITY=10
Multithreading
:: Thread priorities
22. 22
class A extends Thread
{
public void run()
{
System.out.println("Thread A started");
for(int i=1;i<=4;i++)
{
System.out.println("t From ThreadA: i= "+i);
}
System.out.println("Exit from A");
}
}
class B extends Thread
{
public void run()
{
System.out.println("Thread B started");
for(int j=1;j<=4;j++)
{
System.out.println("t From ThreadB: j= "+j);
}
System.out.println("Exit from B");
}
}
Multithreading
:: Thread priorities
23. 23
class C extends Thread
{
public void run()
{
System.out.println("Thread C started");
for(int k=1;k<=4;k++)
{
System.out.println("t From ThreadC: k= "+k);
}
System.out.println("Exit from C");
}
}
class ThreadPriority
{
public static void main(String args[])
{
A threadA=new A();
B threadB=new B();
C threadC=new C();
threadC.setPriority(Thread.MAX_PRIORITY);
threadB.setPriority(threadA.getPriority()+1);
threadA.setPriority(Thread.MIN_PRIORITY);
System.out.println("Started Thread A");
threadA.start();
System.out.println("Started Thread B");
threadB.start();
System.out.println("Started Thread C");
threadC.start();
System.out.println("End of main thread");
}
}
Multithreading
:: Thread priorities
24. 24
Thread synchronization
Threads may execute in a manner where their paths of execution are completely independent of each
other. Neither thread depends upon the other for assistance. For example, one thread might execute a
print job, while a second thread repaints a window. And then there are threads that require
synchronization, the act of serializing access to critical sections of code, at various moments during their
executions. For example, say that two threads need to send data packets over a single network
connection. Each thread must be able to send its entire data packet before the other thread starts
sending its data packet; otherwise, the data is scrambled. This scenario requires each thread to
synchronize its access to the code that does the actual data-packet sending.
Correctly synchronizing threads is one of the more challenging thread-related skills for Java developers
to master.
1. Two or more threads accessing the same data simultaneously may lead to loss of data integrity. In
order to avoid this java uses the concept of monitor. A monitor is an object used as a mutually exclusive
lock.
2. At a time only one thread can access the Monitor. A second thread cannot enter the monitor until the
first comes out. Till such time the other thread is said to be waiting.
3. The keyword Synchronized is used in the code to enable synchronization and it can be used along
with a method.
25. 25
Applications Access to Shared Resources need to be
coordinated.
Printer (two jobs cannot be printed at the same time)
Simultaneous operations on your bank account.
Can the following operations be done at the same time on the
same account?
Deposit()
Withdraw()
Enquire()
Thread synchronization
26. 26
If one thread tries to read the data and other thread tries
to update the same data, it leads to inconsistent state.
This can be prevented by synchronising access to the
data.
Use “Synchronized” methods:
public synchronized void update()
{
…
}
Thread synchronization
:: Synchronized methods