This document discusses various programming paradigms and concurrency concepts in Java. It covers single and multi-process programming, multi-threading, processes, threads, synchronization, deadlocks, and strategies for designing objects to be thread-safe such as immutability, locking, and containment. It also summarizes high-level concurrency utilities in Java like locks, executors, concurrent collections, and atomic variables.
Oracle Enterprise Manager (EM) provides complete lifecycle management for the cloud - from automated cloud setup to self-service delivery to cloud operations. In this session you’ll learn how to take control of your cloud infrastructure with EM features including Consolidation Planning and Self-Service provisioning with Metering and Chargeback. Come hear how Oracle is expanding its management capabilities into the cloud!
(As presented by Adeesh Fulay at Oracle Technology Network Architect Day in Chicago, October 24, 2011.)
oops concept in java | object oriented programming in javaCPD INDIA
object oriented programming is a key concept for the development of application in windows as well as web based application environment. oops concept maps real world through its concept of classes, objects, inheritance, polymorphism which help in making a robust application.
In deploying MySQL, scale-out techniques can be used to scale out reads, but for scaling out writes, other techniques have to be used. To distribute writes over a cluster, it is necessary to shard the database and store the shards on separate servers. This session provides a brief introduction to traditional MySQL scale-out techniques in preparation for a discussion on the different sharding techniques that can be used with MySQL server and how they can be implemented with PHP. You will learn about static and dynamic sharding schemes, their advantages and drawbacks, techniques for locating and moving shards, and techniques for resharding.
Oracle Enterprise Manager (EM) provides complete lifecycle management for the cloud - from automated cloud setup to self-service delivery to cloud operations. In this session you’ll learn how to take control of your cloud infrastructure with EM features including Consolidation Planning and Self-Service provisioning with Metering and Chargeback. Come hear how Oracle is expanding its management capabilities into the cloud!
(As presented by Adeesh Fulay at Oracle Technology Network Architect Day in Chicago, October 24, 2011.)
oops concept in java | object oriented programming in javaCPD INDIA
object oriented programming is a key concept for the development of application in windows as well as web based application environment. oops concept maps real world through its concept of classes, objects, inheritance, polymorphism which help in making a robust application.
In deploying MySQL, scale-out techniques can be used to scale out reads, but for scaling out writes, other techniques have to be used. To distribute writes over a cluster, it is necessary to shard the database and store the shards on separate servers. This session provides a brief introduction to traditional MySQL scale-out techniques in preparation for a discussion on the different sharding techniques that can be used with MySQL server and how they can be implemented with PHP. You will learn about static and dynamic sharding schemes, their advantages and drawbacks, techniques for locating and moving shards, and techniques for resharding.
It is easy to monitor the performance of JVM if one knows how GC and Threads work in JVM. This presentation throws light on Collector types, HotSpot Collection Algorithms, Thread Monitoring, Method Profiling and Heap Profiling
Spring - Part 2 - Autowiring, Annotations, Java based Configuration - slidesHitesh-Java
In this Java Spring Training session, you will learn Spring AOP – Aspect Oriented Programming. Topics covered in this session are:
For more information, visit this link:
• Spring framework
• Inversion of Control
• Dependency Injection – Two types
• Defining beans using XML
• Inheriting beans
• Auto-wiring
• Annotations based configuration
• Java based configuration
https://www.mindsmapped.com/courses/software-development/spring-fundamentals-learn-spring-framework-and-spring-boot/
Amazon DynamoDB is a fast and flexible NoSQL database service for all applications that need consistent, single-digit millisecond latency at any scale. It is a fully managed cloud database and supports both document and key-value store models. Its flexible data model, reliable performance, and automatic scaling of throughput capacity, makes it a great fit for mobile, web, gaming, ad tech, IoT, and many other applications. We’ll take a look at how DynamoDB works and how it can be accelerated by DAX, the DynamoDB Accelerator.
Speaker: Lex Crosett - Solutions Architect, AWS
YouTube Link: https://youtu.be/xuH81XGWeGQ
** Microservices Architecture Training: https://www.edureka.co/microservices-architecture-training**
This Edureka's PPT on Microservices Design Patterns talks about the top design patterns you can use to build applications.
Follow us to never miss an update in the future.
YouTube: https://www.youtube.com/user/edurekaIN
Instagram: https://www.instagram.com/edureka_learning/
Facebook: https://www.facebook.com/edurekaIN/
Twitter: https://twitter.com/edurekain
LinkedIn: https://www.linkedin.com/company/edureka
Castbox: https://castbox.fm/networks/505?country=in
Microservices with Java, Spring Boot and Spring CloudEberhard Wolff
Spring Boot makes creating small Java application easy - and also facilitates operations and deployment. But for Microservices need more: Because Microservices are a distributed systems issues like Service Discovery or Load Balancing must be solved. Spring Cloud adds those capabilities to Spring Boot using e.g. the Netflix stack. This talks covers Spring Boot and Spring Cloud and shows how these technologies can be used to create a complete Microservices environment.
Every bit of JavaScript code runs inside an Execution Context. This key principle is the base of the closures. Mastering closures is key when writing JS code and apps.
The more components a system has, the more challenging its maintenance becomes. Oracle Exadata marries storage with computation through a fast, reliable network, and patching all of these seems daunting. Many companies seem to struggle with it, with some even avoiding it altogether by keeping it “pending.” This session presents tested, applied, and working tips to make the Oracle Exadata patching experience smooth as silk, like vacationing in Hawaii.
Spring Data is a high level SpringSource project whose purpose is to unify and ease the access to different kinds of persistence stores, both relational database systems and NoSQL data stores.
Are you using Java8 Lambdas & Streams in your core business logic? Then you might be having this strange feeling that it’s not Java anymore: at times it’s cryptic, barely readable.. This was the topic of the workshop with the same name that I held at VoxxedDays Bucharest 2017. These are the slides backing the that workshop.
As a summary, the materials walk through the functional features of Java8, adding details along the way about how we can keep the code clean as we embrace the Java 8 features.
The entire desktop screencast + voice it's on youtube, here: https://youtu.be/uH9A37k2QkU
It is easy to monitor the performance of JVM if one knows how GC and Threads work in JVM. This presentation throws light on Collector types, HotSpot Collection Algorithms, Thread Monitoring, Method Profiling and Heap Profiling
Spring - Part 2 - Autowiring, Annotations, Java based Configuration - slidesHitesh-Java
In this Java Spring Training session, you will learn Spring AOP – Aspect Oriented Programming. Topics covered in this session are:
For more information, visit this link:
• Spring framework
• Inversion of Control
• Dependency Injection – Two types
• Defining beans using XML
• Inheriting beans
• Auto-wiring
• Annotations based configuration
• Java based configuration
https://www.mindsmapped.com/courses/software-development/spring-fundamentals-learn-spring-framework-and-spring-boot/
Amazon DynamoDB is a fast and flexible NoSQL database service for all applications that need consistent, single-digit millisecond latency at any scale. It is a fully managed cloud database and supports both document and key-value store models. Its flexible data model, reliable performance, and automatic scaling of throughput capacity, makes it a great fit for mobile, web, gaming, ad tech, IoT, and many other applications. We’ll take a look at how DynamoDB works and how it can be accelerated by DAX, the DynamoDB Accelerator.
Speaker: Lex Crosett - Solutions Architect, AWS
YouTube Link: https://youtu.be/xuH81XGWeGQ
** Microservices Architecture Training: https://www.edureka.co/microservices-architecture-training**
This Edureka's PPT on Microservices Design Patterns talks about the top design patterns you can use to build applications.
Follow us to never miss an update in the future.
YouTube: https://www.youtube.com/user/edurekaIN
Instagram: https://www.instagram.com/edureka_learning/
Facebook: https://www.facebook.com/edurekaIN/
Twitter: https://twitter.com/edurekain
LinkedIn: https://www.linkedin.com/company/edureka
Castbox: https://castbox.fm/networks/505?country=in
Microservices with Java, Spring Boot and Spring CloudEberhard Wolff
Spring Boot makes creating small Java application easy - and also facilitates operations and deployment. But for Microservices need more: Because Microservices are a distributed systems issues like Service Discovery or Load Balancing must be solved. Spring Cloud adds those capabilities to Spring Boot using e.g. the Netflix stack. This talks covers Spring Boot and Spring Cloud and shows how these technologies can be used to create a complete Microservices environment.
Every bit of JavaScript code runs inside an Execution Context. This key principle is the base of the closures. Mastering closures is key when writing JS code and apps.
The more components a system has, the more challenging its maintenance becomes. Oracle Exadata marries storage with computation through a fast, reliable network, and patching all of these seems daunting. Many companies seem to struggle with it, with some even avoiding it altogether by keeping it “pending.” This session presents tested, applied, and working tips to make the Oracle Exadata patching experience smooth as silk, like vacationing in Hawaii.
Spring Data is a high level SpringSource project whose purpose is to unify and ease the access to different kinds of persistence stores, both relational database systems and NoSQL data stores.
Are you using Java8 Lambdas & Streams in your core business logic? Then you might be having this strange feeling that it’s not Java anymore: at times it’s cryptic, barely readable.. This was the topic of the workshop with the same name that I held at VoxxedDays Bucharest 2017. These are the slides backing the that workshop.
As a summary, the materials walk through the functional features of Java8, adding details along the way about how we can keep the code clean as we embrace the Java 8 features.
The entire desktop screencast + voice it's on youtube, here: https://youtu.be/uH9A37k2QkU
This is a 3 part series on Java8 Features. Drop me an email for a discussion - singh.marut@gmail.com
https://github.com/singhmarut/java8training
Videos available at my youtube channel https://www.youtube.com/channel/UCBM4yHwfjQ_syW6Lz8kYpmA
This is a 3 part series on Java8 Features. Drop me an email for a discussion - singh.marut@gmail.com
Code is available at https://github.com/singhmarut/java8training
Videos available at my youtube channel https://www.youtube.com/channel/UCBM4yHwfjQ_syW6Lz8kYpmA
This is a 3 part series on Java8 Features. Drop me an email for a discussion - singh.marut@gmail.com
Code is available at https://github.com/singhmarut/java8training
Videos available at my youtube channel https://www.youtube.com/channel/UCBM4yHwfjQ_syW6Lz8kYpmA
Presented at JavaOne 2013, Tuesday September 24.
"Data Modeling Patterns" co-created with Ian Robinson.
"Pitfalls and Anti-Patterns" created by Ian Robinson.
Apache Camel is swiss knife for integration architectural problems. A full implementation of EIP and Loaded with hundreds of components it is the de-facto standard in solving Integration problems.
Presentation related to the Java Hands-On Workshop I had conducted at MVJ College Of Engineering, Bengaluru.
The code examples and exercises related to the workshop can be found at https://github.com/arpoladia/java-hands-on-workshop.
Credits go to the book Thinking in Java by Bruce Eckel (http://www.mindviewinc.com/Books/TIJ4/). I strongly recommend all Java programmers to buy and read this book cover to cover.
Java 8 introduces new toolkit which enables new model of thinking for java developers – functional. It encourage us to rethink traditional approaches of Object Oriented programming which were commonly accepted for decades. In this talk we will review many Gang of Four design patterns showing how they can be re-implemented in more concise and often more simple and elegant ways. Also we will look beyond that and will see which new design patterns and programming technics functional thinking and new java toolkit bring for us.
This presentation is about advanced multithreading and concurrency in Java. I have tried my best to explain the concepts with code. Feel free to reach me if you have any questions or concerns.
Java has a solid Memory Model, and there are a couple of excellent libraries for concurrency. When you start working with threads however, pitfalls start appearing - especially if the program is supposed to be fast and correct. This session shows proven solutions for some typical problems, showing how to view program code from a concurrency perspective: Which threads share which data, and how? How to reduce the impact of locks? How to avoid them altogether - and when is that worth it?
Aim of this presentation is not to make you masters in Java 8 Concurrency, but to help you guide towards that goal. Sometimes it helps just to know that there is some API that might be suitable for a particular situation. Make use of the pointers given to search more and learn more on those topics. Refer to books, Java API Documentation, Blogs etc. to learn more. Examples and demos for all cases discussed will be added to my blog www.javajee.com.
Concurrency Programming in Java - 05 - Processes and Threads, Thread Objects,...Sachintha Gunasena
This session discusses about the basic building blocks of Concurrent Programming in Java, which include:
processes, threads, how to define a thread, how to start a thread, how to sleep a thread, thread interrupt, interrupt status flag, joins, simple thread example, synchronization part 1, thread interference, memory consistency errors
Thread vs Process
scheduling
synchronization
The thread begins execution with the C/C run-time library startup code.
The startup code calls your main or WinMain and execution continues until the main function returns and the C/C library code calls ExitProcess.
Reflection is the ability of a managed code to read its own metadata for the purpose of finding assemblies, modules and type information at runtime. The classes that give access to the metadata of a running program are in System.Reflection.
System.Reflection namespace defines the following types to analyze the module's metadata of an assembly:
Assembly, Module, Enum, ParameterInfo, MemberInfo, Type, MethodInfo, ConstructorInfo, FieldInfo, EventInfo, and PropertyInfo
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualityInflectra
In this insightful webinar, Inflectra explores how artificial intelligence (AI) is transforming software development and testing. Discover how AI-powered tools are revolutionizing every stage of the software development lifecycle (SDLC), from design and prototyping to testing, deployment, and monitoring.
Learn about:
• The Future of Testing: How AI is shifting testing towards verification, analysis, and higher-level skills, while reducing repetitive tasks.
• Test Automation: How AI-powered test case generation, optimization, and self-healing tests are making testing more efficient and effective.
• Visual Testing: Explore the emerging capabilities of AI in visual testing and how it's set to revolutionize UI verification.
• Inflectra's AI Solutions: See demonstrations of Inflectra's cutting-edge AI tools like the ChatGPT plugin and Azure Open AI platform, designed to streamline your testing process.
Whether you're a developer, tester, or QA professional, this webinar will give you valuable insights into how AI is shaping the future of software delivery.
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...DanBrown980551
Do you want to learn how to model and simulate an electrical network from scratch in under an hour?
Then welcome to this PowSyBl workshop, hosted by Rte, the French Transmission System Operator (TSO)!
During the webinar, you will discover the PowSyBl ecosystem as well as handle and study an electrical network through an interactive Python notebook.
PowSyBl is an open source project hosted by LF Energy, which offers a comprehensive set of features for electrical grid modelling and simulation. Among other advanced features, PowSyBl provides:
- A fully editable and extendable library for grid component modelling;
- Visualization tools to display your network;
- Grid simulation tools, such as power flows, security analyses (with or without remedial actions) and sensitivity analyses;
The framework is mostly written in Java, with a Python binding so that Python developers can access PowSyBl functionalities as well.
What you will learn during the webinar:
- For beginners: discover PowSyBl's functionalities through a quick general presentation and the notebook, without needing any expert coding skills;
- For advanced developers: master the skills to efficiently apply PowSyBl functionalities to your real-world scenarios.
Key Trends Shaping the Future of Infrastructure.pdfCheryl Hung
Keynote at DIGIT West Expo, Glasgow on 29 May 2024.
Cheryl Hung, ochery.com
Sr Director, Infrastructure Ecosystem, Arm.
The key trends across hardware, cloud and open-source; exploring how these areas are likely to mature and develop over the short and long-term, and then considering how organisations can position themselves to adapt and thrive.
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...James Anderson
Effective Application Security in Software Delivery lifecycle using Deployment Firewall and DBOM
The modern software delivery process (or the CI/CD process) includes many tools, distributed teams, open-source code, and cloud platforms. Constant focus on speed to release software to market, along with the traditional slow and manual security checks has caused gaps in continuous security as an important piece in the software supply chain. Today organizations feel more susceptible to external and internal cyber threats due to the vast attack surface in their applications supply chain and the lack of end-to-end governance and risk management.
The software team must secure its software delivery process to avoid vulnerability and security breaches. This needs to be achieved with existing tool chains and without extensive rework of the delivery processes. This talk will present strategies and techniques for providing visibility into the true risk of the existing vulnerabilities, preventing the introduction of security issues in the software, resolving vulnerabilities in production environments quickly, and capturing the deployment bill of materials (DBOM).
Speakers:
Bob Boule
Robert Boule is a technology enthusiast with PASSION for technology and making things work along with a knack for helping others understand how things work. He comes with around 20 years of solution engineering experience in application security, software continuous delivery, and SaaS platforms. He is known for his dynamic presentations in CI/CD and application security integrated in software delivery lifecycle.
Gopinath Rebala
Gopinath Rebala is the CTO of OpsMx, where he has overall responsibility for the machine learning and data processing architectures for Secure Software Delivery. Gopi also has a strong connection with our customers, leading design and architecture for strategic implementations. Gopi is a frequent speaker and well-known leader in continuous delivery and integrating security into software delivery.
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Jeffrey Haguewood
Sidekick Solutions uses Bonterra Impact Management (fka Social Solutions Apricot) and automation solutions to integrate data for business workflows.
We believe integration and automation are essential to user experience and the promise of efficient work through technology. Automation is the critical ingredient to realizing that full vision. We develop integration products and services for Bonterra Case Management software to support the deployment of automations for a variety of use cases.
This video focuses on the notifications, alerts, and approval requests using Slack for Bonterra Impact Management. The solutions covered in this webinar can also be deployed for Microsoft Teams.
Interested in deploying notification automations for Bonterra Impact Management? Contact us at sales@sidekicksolutionsllc.com to discuss next steps.
Transcript: Selling digital books in 2024: Insights from industry leaders - T...BookNet Canada
The publishing industry has been selling digital audiobooks and ebooks for over a decade and has found its groove. What’s changed? What has stayed the same? Where do we go from here? Join a group of leading sales peers from across the industry for a conversation about the lessons learned since the popularization of digital books, best practices, digital book supply chain management, and more.
Link to video recording: https://bnctechforum.ca/sessions/selling-digital-books-in-2024-insights-from-industry-leaders/
Presented by BookNet Canada on May 28, 2024, with support from the Department of Canadian Heritage.
UiPath Test Automation using UiPath Test Suite series, part 4DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 4. In this session, we will cover Test Manager overview along with SAP heatmap.
The UiPath Test Manager overview with SAP heatmap webinar offers a concise yet comprehensive exploration of the role of a Test Manager within SAP environments, coupled with the utilization of heatmaps for effective testing strategies.
Participants will gain insights into the responsibilities, challenges, and best practices associated with test management in SAP projects. Additionally, the webinar delves into the significance of heatmaps as a visual aid for identifying testing priorities, areas of risk, and resource allocation within SAP landscapes. Through this session, attendees can expect to enhance their understanding of test management principles while learning practical approaches to optimize testing processes in SAP environments using heatmap visualization techniques
What will you get from this session?
1. Insights into SAP testing best practices
2. Heatmap utilization for testing
3. Optimization of testing processes
4. Demo
Topics covered:
Execution from the test manager
Orchestrator execution result
Defect reporting
SAP heatmap example with demo
Speaker:
Deepak Rai, Automation Practice Lead, Boundaryless Group and UiPath MVP
Generating a custom Ruby SDK for your web service or Rails API using Smithyg2nightmarescribd
Have you ever wanted a Ruby client API to communicate with your web service? Smithy is a protocol-agnostic language for defining services and SDKs. Smithy Ruby is an implementation of Smithy that generates a Ruby SDK using a Smithy model. In this talk, we will explore Smithy and Smithy Ruby to learn how to generate custom feature-rich SDKs that can communicate with any web service, such as a Rails JSON API.
GraphRAG is All You need? LLM & Knowledge GraphGuy Korland
Guy Korland, CEO and Co-founder of FalkorDB, will review two articles on the integration of language models with knowledge graphs.
1. Unifying Large Language Models and Knowledge Graphs: A Roadmap.
https://arxiv.org/abs/2306.08302
2. Microsoft Research's GraphRAG paper and a review paper on various uses of knowledge graphs:
https://www.microsoft.com/en-us/research/blog/graphrag-unlocking-llm-discovery-on-narrative-private-data/
Securing your Kubernetes cluster_ a step-by-step guide to success !KatiaHIMEUR1
Today, after several years of existence, an extremely active community and an ultra-dynamic ecosystem, Kubernetes has established itself as the de facto standard in container orchestration. Thanks to a wide range of managed services, it has never been so easy to set up a ready-to-use Kubernetes cluster.
However, this ease of use means that the subject of security in Kubernetes is often left for later, or even neglected. This exposes companies to significant risks.
In this talk, I'll show you step-by-step how to secure your Kubernetes cluster for greater peace of mind and reliability.
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Ramesh Iyer
In today's fast-changing business world, Companies that adapt and embrace new ideas often need help to keep up with the competition. However, fostering a culture of innovation takes much work. It takes vision, leadership and willingness to take risks in the right proportion. Sachin Dev Duggal, co-founder of Builder.ai, has perfected the art of this balance, creating a company culture where creativity and growth are nurtured at each stage.
3. Process
• Process
A process runs independently and isolated of
other processes. It cannot directly access
shared data in other processes. The resources
of the process are allocated to it via the
operating system, e.g. memory and CPU time.
4. Java Process
Objects
• ADTs, aggregate components, JavaBeans, monitors,
business objects, remote RMI objects, subsystems, ...
• May be grouped according to structure, role, ...
• Usable across multiple activities — focus on SAFETY
Activities
• Messages, call chains, threads, sessions, scenarios,
scripts, workflows, use cases, transactions, data flows,
mobile computations
5. Thread
• Threads are so called lightweight processes
which have their own call stack but an access
shared data. Every thread has its own memory
cache. If a thread reads shared data it stores
this data in its own memory cache. A thread
can re-read the shared data
6. What is The Gain
• Amdahl's Law
• It states that a small portion of the program which
cannot be parallelized will limit the overall speed-up
available from parallelization.
• A program solving a large mathematical or engineering
problem will typically consist of several parallelizable
parts and several non-parallelizable (sequential) parts.
If p is the fraction of running time a sequential program
spends on non-parallelizable parts, then
• S = 1/p
7. How much is the speed up
• If the sequential portion of a program accounts
for 10% of the runtime, we can get no more than
a 10× speed-up, regardless of how many
processors are added. This puts an upper limit on
the usefulness of adding more parallel execution
units. "When a task cannot be partitioned
because of sequential constraints, the application
of more effort has no effect on the schedule. The
bearing of a child takes nine months, no matter
how many women are assigned
8. How does Java help to Parallel
Programming
• Has Threads since its inception
• Threads have their own stack. But uses heap
of the JVM
• Has many constructs to control the
concurrency
• Programmer knowledge is very critical
10. Thread Class
Constructors
• Thread(Runnable r) constructs so run() calls r.run()
• — Other versions allow names, ThreadGroup placement
Principal methods
• start() activates run() then returns to caller
• isAlive() returns true if started but not stopped
• join() waits for termination (optional timeout)
• interrupt() breaks out of wait, sleep, or join
• isInterrupted() returns interruption state
• getPriority() returns current scheduling priority
• setPriority(int priorityFromONEtoTEN) sets it
11. How to Implement a Thread
• Subclass Thread. The Thread class itself
implements Runnable, though its run method
does nothing. An application can subclass
Thread, providing its own implementation of
run
12. Thread Subclass
public class HelloThread extends Thread {
public void run() {
System.out.println("Hello from a thread!");
}
public static void main(String args[]) {
(new HelloThread()).start();
}
}
13. Implement Runnable Interface
public class HelloRunnable implements Runnable
{
public void run() {
System.out.println("Hello from a thread!"); }
public static void main(String args[]) {
(new HelloRunnable()).start();
}
}
14. Pausing while executing
• Thread.sleep causes the current thread to
suspend execution for a specified period.
• This is an efficient means of making processor
time available to the other threads of an
application or other applications that might be
running on a computer system. The sleep
method can also be used for pacing
15. Thread Management
• To directly control thread creation and
management, simply instantiate Thread each
time the application needs to initiate an
asynchronous task.
• To abstract thread management from the rest
of your application, pass the application's
tasks to an executor.
16. Sleep Example
• main declares that it throws
InterruptedException. This is an exception that
sleep throws when another thread interrupts
the current thread while sleep is active. Since
this application has not defined another
thread to cause the interrupt, it doesn't
bother to catch InterruptedException.
17. Communicating with Thread
• Interrupts
• An interrupt is an indication to a thread that it
should stop what it is doing and do something
else. It's up to the programmer to decide
exactly how a thread responds to an interrupt,
but it is very common for the thread to
terminate. This is the usage emphasized in this
lesson.
18. Interrupt requirement
• A thread sends an interrupt by invoking
interrupt on the Thread object for the thread
to be interrupted. For the interrupt
mechanism to work correctly, the interrupted
thread must support its own interruption.
19. Interrupt Status
• The interrupt mechanism is implemented
using an internal flag known as the interrupt
status. Invoking Thread.interrupt sets this flag.
When a thread checks for an interrupt by
invoking the static method
Thread.interrupted, interrupt status is cleared.
The non-static isInterrupted method, which is
used by one thread to query the interrupt
status of another, does not change the
interrupt status flag.
20. Interrupted Exception and Status
• By convention, any method that exits by
throwing an InterruptedException clears
interrupt status when it does so. However, it's
always possible that interrupt status will
immediately be set again, by another thread
invoking interrupt.
21. Thread Collaboration
• The join method allows one thread to wait for the
completion of another. If t is a Thread object whose
thread is currently executing,
• t.join();
• causes the current thread to pause execution until t's
thread terminates. Overloads of join allow the
programmer to specify a waiting period. However, as
with sleep, join is dependent on the OS for timing, so
you should not assume that join will wait exactly as
long as you specify.
• Like sleep, join responds to an interrupt by exiting with
an InterruptedException.
23. Synchronization
• Threads communicate primarily by sharing
access to fields and the objects reference
fields refer to. This form of communication is
extremely efficient, but makes two kinds of
errors possible: thread interference and
memory consistency errors. The tool needed
to prevent these errors is synchronization.
24. Synchronization Mechanisms
• Thread Interference describes how errors are introduced
when multiple threads access shared data.
• Memory Consistency Errors describes errors that result
from inconsistent views of shared memory.
• Synchronized Methods describes a simple idiom that can
effectively prevent thread interference and memory
consistency errors.
• Implicit Locks and Synchronization describes a more
general synchronization idiom, and describes how
synchronization is based on implicit locks.
• Atomic Access talks about the general idea of operations
that can't be interfered with by other threads.
25. Synchronization Libraries
Semaphores
Maintain count of the number of threads allowed to pass
Latches
Boolean conditions that are set once, ever
Barriers
Counters that cause all threads to wait until all have
finished
Reentrant Locks
Java-style locks allowing multiple acquisition by same
thread, but that may be acquired and released as needed
Mutexes
Non-reentrant locks
Read/Write Locks
Pairs of conditions in which the readLock may be shared,
but the writeLock is exclusive
26. Semaphores
Conceptually serve as permit holders
• Construct with an initial number of permits (usually 0)
• require waits for a permit to be available, then takes one
• release adds a permit But in normal implementations, no actual
permits change hands.
• The semaphore just maintains the current count.
• Enables very efficient implementation
Applications
• Isolating wait sets in buffers, resource controllers
• Designs that would otherwise encounter missed signals
— Where one thread signals before the other has even
started waiting
— Semaphores ‘remember’ how many times they were signalled
27. Counter Using Semaphores
class BoundedCounterUsingSemaphores {
long count_ = MIN;
Sync decPermits_= new Semaphore(0);
Sync incPermits_= new Semaphore(MAX-MIN);
synchronized long value() { return count_; }
void inc() throws InterruptedException {
incPermits_.acquire();
synchronized(this) { ++count_; }
decPermits_.release();
}
void dec() throws InterruptedException {
decPermits_.acquire();
synchronized(this) { --count_; }
incPermits_.release();
}
}
28. Using Latches
• Conditions starting out false, but once set
true, remain true forever
• Initialization flags
• End-of-stream conditions
• Thread termination
• Event occurrence
29. Using Barrier Conditions
Count-based latches
• Initialize with a fixed count
• Each release monotonically decrements count
• All acquires pass when count reaches zero
30. Liveness
• A concurrent application's ability to execute in
a timely manner is known as its liveness. This
section describes the most common kind of
liveness problem, deadlock, and goes on to
briefly describe two other liveness problems,
starvation and livelock.
31. Deadlock
• Deadlock describes a situation where two or
more threads are blocked forever, waiting for
each other. Here's an example.
• Alphonse and Gaston are friends, and great
believers in courtesy. A strict rule of courtesy is
that when you bow to a friend, you must remain
bowed until your friend has a chance to return
the bow. Unfortunately, this rule does not
account for the possibility that two friends might
bow to each other at the same time.
32. Starvation and Livelock
• Starvation describes a situation where a thread is
unable to gain regular access to shared resources
and is unable to make progress. This happens
when shared resources are made unavailable for
long periods by "greedy" threads.
• A thread often acts in response to the action of
another thread. If the other thread's action is also
a response to the action of another thread, then
livelock may result.
33. Guarded Blocks
• Threads often have to coordinate their
actions. The most common coordination idiom
is the guarded block. Such a block begins by
polling a condition that must be true before
the block can proceed. There are a number of
steps to follow in order to do this correctly.
34. Guarded Block (cont..)
• Constant polling for Condition
• Use wait/notify method
• Immutable Objects
• Producer Consumer Example
• A Synchronized Class Example
35. Immutable Object
1. Don't provide "setter" methods — methods that modify fields or
objects referred to by fields.
2. Make all fields final and private.
3. Don't allow subclasses to override methods. The simplest way to
do this is to declare the class as final. A more sophisticated
approach is to make the constructor private and construct
instances in factory methods.
4. If the instance fields include references to mutable objects, don't
allow those objects to be changed:
– Don't provide methods that modify the mutable objects.
– Don't share references to the mutable objects. Never store
references to external, mutable objects passed to the constructor; if
necessary, create copies, and store references to the copies.
Similarly, create copies of your internal mutable objects when
necessary to avoid returning the originals in your methods.
36. High Level Concurrency Objects
• Lock objects support locking idioms that simplify many
concurrent applications.
• Executors define a high-level API for launching and
managing threads. Executor implementations provided by
java.util.concurrent provide thread pool management
suitable for large-scale applications.
• Concurrent collections make it easier to manage large
collections of data, and can greatly reduce the need for
synchronization.
• Atomic variables have features that minimize
synchronization and help avoid memory consistency errors.
• ThreadLocalRandom (in JDK 7) provides efficient generation
of pseudorandom numbers from multiple threads.
37. Lock Objects
• Only one thread can own a implicit Lock object at a
time. Lock objects also support a wait/notify
mechanism, through their associated Condition
objects.
• The biggest advantage of Lock objects over implicit
locks is their ability to back out of an attempt to
acquire a lock. The tryLock method backs out if the
lock is not available immediately or before a timeout
expires (if specified). The lockInterruptibly method
backs out if another thread sends an interrupt before
the lock is acquired.
39. Executors
• In large-scale applications, it makes sense to
separate thread management and creation from
the rest of the application. Objects that
encapsulate these functions are known as
executors.
• Executor Interfaces define the three executor
object types.
• Thread Pools are the most common kind of
executor implementation.
• Fork/Join is a framework (new in JDK 7) for taking
advantage of multiple processors.
40. Executor Interfaces
• The java.util.concurrent package defines three
executor interfaces:
• Executor, a simple interface that supports
launching new tasks.
• ExecutorService, a subinterface of Executor,
which adds features that help manage the
lifecycle, both of the individual tasks and of the
executor itself.
• ScheduledExecutorService, a subinterface of
ExecutorService, supports future and/or periodic
execution of tasks.
41. The Executor Interface
• The Executor interface provides a single
method, execute, designed to be a drop-in
replacement for a common thread-creation
idiom. If r is a Runnable object, and e is an
Executor object you can replace
• (new Thread(r)).start();
• with
• e.execute(r);
42. The ExecutorService Interface
• The ExecutorService interface supplements execute with
a similar, but more versatile submit method. Like
execute, submit accepts Runnable objects, but also
accepts Callable objects, which allow the task to return a
value. The submit method returns a Future object, which
is used to retrieve the Callable return value and to
manage the status of both Callable and Runnable tasks.
• ExecutorService also provides methods for submitting
large collections of Callable objects. Finally,
ExecutorService provides a number of methods for
managing the shutdown of the executor. To support
immediate shutdown, tasks should handle interrupts
correctly.
43. The ScheduledExecutorService
Interface
• The ScheduledExecutorService interface
supplements the methods of its parent
ExecutorService with schedule, which
executes a Runnable or Callable task after a
specified delay. In addition, the interface
defines scheduleAtFixedRate and
scheduleWithFixedDelay, which executes
specified tasks repeatedly, at defined intervals.
44. Thread Pools
• Using worker threads minimizes the overhead
due to thread creation. Thread objects use a
significant amount of memory, and in a large-
scale application, allocating and deallocating
many thread objects creates a significant
memory management overhead.
• Tasks are submitted to the pool via an internal
queue, which holds extra tasks whenever
there are more active tasks than threads.
45. Thread Pools
• newFixedThreadPool
• newCachedThreadPool
• newSingleThreadExecutor
• For customized needs one can construct
• java.util.concurrent.ThreadPoolExecutor or
java.util.concurrent.ScheduledThreadPoolExec
utor
46. Fork/Join
• The fork/join framework is an implementation
of the ExecutorService interface that helps you
take advantage of multiple processors. It is
designed for work that can be broken into
smaller pieces recursively. The goal is to use all
the available processing power to enhance the
performance of your application.
47. Basic Use
• if (my portion of the work is small enough)
– do the work directly
• else
– split my work into two pieces
– invoke the two pieces and wait for the results
• After your ForkJoinTask is ready, create one that
represents all the work to be done and pass it to
the invoke() method of a ForkJoinPool instance.
48. Concurrent Collections
• The java.util.concurrent package includes a
number of additions to the Java Collections
Framework
• BlockingQueue
• ConcurrentMap
• ConcurrentSkipList
• All of these collections help avoid Memory
Consistency Errors by defining a happens-before
relationship between an operation that adds an
object to the collection with subsequent
operations that access or remove that object.
49. Atomic Variables
• The java.util.concurrent.atomic package
defines classes that support atomic operations
on single variables. All classes have get and set
methods that work like reads and writes on
volatile variables.
50. Concurrent Random Numbers
• In JDK 7, java.util.concurrent includes a
convenience class, ThreadLocalRandom, for
applications that expect to use random
numbers from multiple threads or
ForkJoinTasks.
• int r = ThreadLocalRandom.current()
.nextInt(4, 77);
51. Designing Objects for
Concurrency
Patterns for safely representing and managing state
Immutability
• Avoiding interference by avoiding change
Locking
• Guaranteeing exclusive access
State dependence
• What to do when you can’t do anything
Containment
• Hiding internal objects
Splitting
• Separating independent aspects of objects and locks