Developed a multi-thread based Java program for a small barbershop. Customer and Barber arrive at random intervals, with mean and standard deviation. Each barber has a number of chairs in which the customer sits when they are getting their hair cut, this application which was developed in java using LinkedList.
An attempt at finding an optimized working model using Arena for a barber shop ameliorating the customer wait time, thus attracting more customers with minimum cost
An attempt at finding an optimized working model using Arena for a barber shop ameliorating the customer wait time, thus attracting more customers with minimum cost
10/8/2014
1
MATLAB Introduction II
Programming and Scripts
Programming and Scripts
• The simplest type of MATLAB program is
called a script.
• A script is a file with a .m extension that
contains multiple sequential lines of MATLAB
commands and function calls.
• You can run a script by typing its name at the
command line.
10/8/2014
2
Sample Script
• To create a script, use the edit command,
• This opens a blank file named plotrand.m
• Enter some code that plots a vector of random
data:
edit plotrand
n = 50;
r = rand(n,1);
plot(r)
Sample Script
• Next, add code that draws a horizontal line on
the plot at the mean:
m = mean(r);
hold on
plot([0,n],[m,m])
hold off
title('Mean of Random Uniform Data')
10/8/2014
3
Sample Script
• Whenever you write code, it is a good practice to add
comments that describe the code. Comments allow others to
understand your code, and can refresh your memory when you
return to it later. Add comments using the percent (%) symbol.
% Generate random data from a uniform distribution
% and calculate the mean. Plot the data and the mean.
n = 50; % 50 data points
r = rand(n,1);
plot(r)
% Draw a line from (0,m) to (n,m)
m = mean(r);
hold on
plot([0,n],[m,m])
hold off
title('Mean of Random Uniform Data')
Sample Script
• Save the file in the current folder. To run the
script, type its name at the command line:
• You can also run scripts from the Editor by
pressing the Run button, .
plotrand
10/8/2014
4
Sample Script
• You will have something like this.
0 5 10 15 20 25 30 35 40 45 50
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
Mean of Random Uniform Data
Loops and Conditional Statements
• Within a script, you can loop over sections of code
and conditionally execute sections using the
keywords for, while, if, and switch.
• For example, create a script named calcmean.m that
uses a for loop to calculate the mean of five random
samples and the overall mean.
edit calcmean.m
10/8/2014
5
Loops and Conditional Statements
• Now, modify the for loop so that you can view the results
at each iteration. Display text in the Command Window
that includes the current iteration number, and remove
the semicolon from the assignment to sampleMean.
nsamples = 5;
npoints = 50;
for k = 1:nsamples
currentData = rand(npoints,1);
sampleMean(k) = mean(currentData);
end
overallMean = mean(sampleMean)
Loops and Conditional Statements
• When you run the script, it displays the
intermediate results, and then calculates the
overall mean.
for k = 1:nsamples
iterationString = ['Iteration #',int2str(k)];
disp(iterationString)
currentData = rand(npoints,1);
sampleMean(k) = mean(currentData)
end
overallMean = mean(sampleMean)
10/8/2014
6
Loops and Conditional Statements
• You will have something like this in the command
window.
Iteration #1
sampleMean =
0.4899
Iteration #2
sampleMean =
0.4899 0.4505
Iteration #3
sampl.
A MULTIPLE – CHANNEL QUEUING MODELS ON FUZZY ENVIRONMENTIAEME Publication
In this paper, we investigated a queuing model of fuzzy environment-based a multiple channel queuing model (M/M/C) ( /FCFS) and study its performance under realistic conditions. It applies a nonagonal fuzzy number to analyse the relevant performance of a multiple channel queuing model (M/M/C) ( /FCFS). Based on the sub interval average ranking method for nonagonal fuzzy number, we convert fuzzy number to crisp one. Numerical results reveal that the efficiency of this method. Intuitively, the fuzzy environment adapts well to a multiple channel queuing models (M/M/C) ( /FCFS) are very well.
IJERA (International journal of Engineering Research and Applications) is International online, ... peer reviewed journal. For more detail or submit your article, please visit www.ijera.com
Queuing is the common activity of customers or people to avail the desired service, which could be processed or distributed one at a time. Bank ATMs would avoid losing their customers due to a long wait on the line. The bank initially provides one ATM in every branch. But, one ATM would not serve a purpose when customers withdraw to use ATM and try to use other bank ATM. Thus the service time needs to be improved to maintain the customers. This paper shows that the queuing theory used to solve this problem. We obtain the data from a bank ATM in a city. We then derive the arrival rate, service rate, utilization rate, waiting time in the queue and the average number of customers in the queue based on the data using Little’s theorem and M/M/I queuing model. The arrival rate at a bank ATM on Sunday during banking time is 1 customer per minute (cpm) while the service rate is 1.50 cpm. The average number of customer in the ATM is 2 and the utilization period is 0.70. We conclude the paper by discussing the benefits of performing queuing analysis to a busy ATM.
GridMate - End to end testing is a critical piece to ensure quality and avoid...ThomasParaiso2
End to end testing is a critical piece to ensure quality and avoid regressions. In this session, we share our journey building an E2E testing pipeline for GridMate components (LWC and Aura) using Cypress, JSForce, FakerJS…
Communications Mining Series - Zero to Hero - Session 1DianaGray10
This session provides introduction to UiPath Communication Mining, importance and platform overview. You will acquire a good understand of the phases in Communication Mining as we go over the platform with you. Topics covered:
• Communication Mining Overview
• Why is it important?
• How can it help today’s business and the benefits
• Phases in Communication Mining
• Demo on Platform overview
• Q/A
Essentials of Automations: The Art of Triggers and Actions in FMESafe Software
In this second installment of our Essentials of Automations webinar series, we’ll explore the landscape of triggers and actions, guiding you through the nuances of authoring and adapting workspaces for seamless automations. Gain an understanding of the full spectrum of triggers and actions available in FME, empowering you to enhance your workspaces for efficient automation.
We’ll kick things off by showcasing the most commonly used event-based triggers, introducing you to various automation workflows like manual triggers, schedules, directory watchers, and more. Plus, see how these elements play out in real scenarios.
Whether you’re tweaking your current setup or building from the ground up, this session will arm you with the tools and insights needed to transform your FME usage into a powerhouse of productivity. Join us to discover effective strategies that simplify complex processes, enhancing your productivity and transforming your data management practices with FME. Let’s turn complexity into clarity and make your workspaces work wonders!
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.
10/8/2014
1
MATLAB Introduction II
Programming and Scripts
Programming and Scripts
• The simplest type of MATLAB program is
called a script.
• A script is a file with a .m extension that
contains multiple sequential lines of MATLAB
commands and function calls.
• You can run a script by typing its name at the
command line.
10/8/2014
2
Sample Script
• To create a script, use the edit command,
• This opens a blank file named plotrand.m
• Enter some code that plots a vector of random
data:
edit plotrand
n = 50;
r = rand(n,1);
plot(r)
Sample Script
• Next, add code that draws a horizontal line on
the plot at the mean:
m = mean(r);
hold on
plot([0,n],[m,m])
hold off
title('Mean of Random Uniform Data')
10/8/2014
3
Sample Script
• Whenever you write code, it is a good practice to add
comments that describe the code. Comments allow others to
understand your code, and can refresh your memory when you
return to it later. Add comments using the percent (%) symbol.
% Generate random data from a uniform distribution
% and calculate the mean. Plot the data and the mean.
n = 50; % 50 data points
r = rand(n,1);
plot(r)
% Draw a line from (0,m) to (n,m)
m = mean(r);
hold on
plot([0,n],[m,m])
hold off
title('Mean of Random Uniform Data')
Sample Script
• Save the file in the current folder. To run the
script, type its name at the command line:
• You can also run scripts from the Editor by
pressing the Run button, .
plotrand
10/8/2014
4
Sample Script
• You will have something like this.
0 5 10 15 20 25 30 35 40 45 50
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
Mean of Random Uniform Data
Loops and Conditional Statements
• Within a script, you can loop over sections of code
and conditionally execute sections using the
keywords for, while, if, and switch.
• For example, create a script named calcmean.m that
uses a for loop to calculate the mean of five random
samples and the overall mean.
edit calcmean.m
10/8/2014
5
Loops and Conditional Statements
• Now, modify the for loop so that you can view the results
at each iteration. Display text in the Command Window
that includes the current iteration number, and remove
the semicolon from the assignment to sampleMean.
nsamples = 5;
npoints = 50;
for k = 1:nsamples
currentData = rand(npoints,1);
sampleMean(k) = mean(currentData);
end
overallMean = mean(sampleMean)
Loops and Conditional Statements
• When you run the script, it displays the
intermediate results, and then calculates the
overall mean.
for k = 1:nsamples
iterationString = ['Iteration #',int2str(k)];
disp(iterationString)
currentData = rand(npoints,1);
sampleMean(k) = mean(currentData)
end
overallMean = mean(sampleMean)
10/8/2014
6
Loops and Conditional Statements
• You will have something like this in the command
window.
Iteration #1
sampleMean =
0.4899
Iteration #2
sampleMean =
0.4899 0.4505
Iteration #3
sampl.
A MULTIPLE – CHANNEL QUEUING MODELS ON FUZZY ENVIRONMENTIAEME Publication
In this paper, we investigated a queuing model of fuzzy environment-based a multiple channel queuing model (M/M/C) ( /FCFS) and study its performance under realistic conditions. It applies a nonagonal fuzzy number to analyse the relevant performance of a multiple channel queuing model (M/M/C) ( /FCFS). Based on the sub interval average ranking method for nonagonal fuzzy number, we convert fuzzy number to crisp one. Numerical results reveal that the efficiency of this method. Intuitively, the fuzzy environment adapts well to a multiple channel queuing models (M/M/C) ( /FCFS) are very well.
IJERA (International journal of Engineering Research and Applications) is International online, ... peer reviewed journal. For more detail or submit your article, please visit www.ijera.com
Queuing is the common activity of customers or people to avail the desired service, which could be processed or distributed one at a time. Bank ATMs would avoid losing their customers due to a long wait on the line. The bank initially provides one ATM in every branch. But, one ATM would not serve a purpose when customers withdraw to use ATM and try to use other bank ATM. Thus the service time needs to be improved to maintain the customers. This paper shows that the queuing theory used to solve this problem. We obtain the data from a bank ATM in a city. We then derive the arrival rate, service rate, utilization rate, waiting time in the queue and the average number of customers in the queue based on the data using Little’s theorem and M/M/I queuing model. The arrival rate at a bank ATM on Sunday during banking time is 1 customer per minute (cpm) while the service rate is 1.50 cpm. The average number of customer in the ATM is 2 and the utilization period is 0.70. We conclude the paper by discussing the benefits of performing queuing analysis to a busy ATM.
GridMate - End to end testing is a critical piece to ensure quality and avoid...ThomasParaiso2
End to end testing is a critical piece to ensure quality and avoid regressions. In this session, we share our journey building an E2E testing pipeline for GridMate components (LWC and Aura) using Cypress, JSForce, FakerJS…
Communications Mining Series - Zero to Hero - Session 1DianaGray10
This session provides introduction to UiPath Communication Mining, importance and platform overview. You will acquire a good understand of the phases in Communication Mining as we go over the platform with you. Topics covered:
• Communication Mining Overview
• Why is it important?
• How can it help today’s business and the benefits
• Phases in Communication Mining
• Demo on Platform overview
• Q/A
Essentials of Automations: The Art of Triggers and Actions in FMESafe Software
In this second installment of our Essentials of Automations webinar series, we’ll explore the landscape of triggers and actions, guiding you through the nuances of authoring and adapting workspaces for seamless automations. Gain an understanding of the full spectrum of triggers and actions available in FME, empowering you to enhance your workspaces for efficient automation.
We’ll kick things off by showcasing the most commonly used event-based triggers, introducing you to various automation workflows like manual triggers, schedules, directory watchers, and more. Plus, see how these elements play out in real scenarios.
Whether you’re tweaking your current setup or building from the ground up, this session will arm you with the tools and insights needed to transform your FME usage into a powerhouse of productivity. Join us to discover effective strategies that simplify complex processes, enhancing your productivity and transforming your data management practices with FME. Let’s turn complexity into clarity and make your workspaces work wonders!
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.
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionAggregage
Join Maher Hanafi, VP of Engineering at Betterworks, in this new session where he'll share a practical framework to transform Gen AI prototypes into impactful products! He'll delve into the complexities of data collection and management, model selection and optimization, and ensuring security, scalability, and responsible use.
Sudheer Mechineni, Head of Application Frameworks, Standard Chartered Bank
Discover how Standard Chartered Bank harnessed the power of Neo4j to transform complex data access challenges into a dynamic, scalable graph database solution. This keynote will cover their journey from initial adoption to deploying a fully automated, enterprise-grade causal cluster, highlighting key strategies for modelling organisational changes and ensuring robust disaster recovery. Learn how these innovations have not only enhanced Standard Chartered Bank’s data infrastructure but also positioned them as pioneers in the banking sector’s adoption of graph technology.
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...SOFTTECHHUB
The choice of an operating system plays a pivotal role in shaping our computing experience. For decades, Microsoft's Windows has dominated the market, offering a familiar and widely adopted platform for personal and professional use. However, as technological advancements continue to push the boundaries of innovation, alternative operating systems have emerged, challenging the status quo and offering users a fresh perspective on computing.
One such alternative that has garnered significant attention and acclaim is Nitrux Linux 3.5.0, a sleek, powerful, and user-friendly Linux distribution that promises to redefine the way we interact with our devices. With its focus on performance, security, and customization, Nitrux Linux presents a compelling case for those seeking to break free from the constraints of proprietary software and embrace the freedom and flexibility of open-source computing.
Maruthi Prithivirajan, Head of ASEAN & IN Solution Architecture, Neo4j
Get an inside look at the latest Neo4j innovations that enable relationship-driven intelligence at scale. Learn more about the newest cloud integrations and product enhancements that make Neo4j an essential choice for developers building apps with interconnected data and generative AI.
Pushing the limits of ePRTC: 100ns holdover for 100 daysAdtran
At WSTS 2024, Alon Stern explored the topic of parametric holdover and explained how recent research findings can be implemented in real-world PNT networks to achieve 100 nanoseconds of accuracy for up to 100 days.
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...Neo4j
Leonard Jayamohan, Partner & Generative AI Lead, Deloitte
This keynote will reveal how Deloitte leverages Neo4j’s graph power for groundbreaking digital twin solutions, achieving a staggering 100x performance boost. Discover the essential role knowledge graphs play in successful generative AI implementations. Plus, get an exclusive look at an innovative Neo4j + Generative AI solution Deloitte is developing in-house.
DevOps and Testing slides at DASA ConnectKari Kakkonen
My and Rik Marselis slides at 30.5.2024 DASA Connect conference. We discuss about what is testing, then what is agile testing and finally what is Testing in DevOps. Finally we had lovely workshop with the participants trying to find out different ways to think about quality and testing in different parts of the DevOps infinity loop.
In his public lecture, Christian Timmerer provides insights into the fascinating history of video streaming, starting from its humble beginnings before YouTube to the groundbreaking technologies that now dominate platforms like Netflix and ORF ON. Timmerer also presents provocative contributions of his own that have significantly influenced the industry. He concludes by looking at future challenges and invites the audience to join in a discussion.
Climate Impact of Software Testing at Nordic Testing DaysKari Kakkonen
My slides at Nordic Testing Days 6.6.2024
Climate impact / sustainability of software testing discussed on the talk. ICT and testing must carry their part of global responsibility to help with the climat warming. We can minimize the carbon footprint but we can also have a carbon handprint, a positive impact on the climate. Quality characteristics can be added with sustainability, and then measured continuously. Test environments can be used less, and in smaller scale and on demand. Test techniques can be used in optimizing or minimizing number of tests. Test automation can be used to speed up testing.
Threats to mobile devices are more prevalent and increasing in scope and complexity. Users of mobile devices desire to take full advantage of the features
available on those devices, but many of the features provide convenience and capability but sacrifice security. This best practices guide outlines steps the users can take to better protect personal devices and information.
Epistemic Interaction - tuning interfaces to provide information for AI supportAlan Dix
Paper presented at SYNERGY workshop at AVI 2024, Genoa, Italy. 3rd June 2024
https://alandix.com/academic/papers/synergy2024-epistemic/
As machine learning integrates deeper into human-computer interactions, the concept of epistemic interaction emerges, aiming to refine these interactions to enhance system adaptability. This approach encourages minor, intentional adjustments in user behaviour to enrich the data available for system learning. This paper introduces epistemic interaction within the context of human-system communication, illustrating how deliberate interaction design can improve system understanding and adaptation. Through concrete examples, we demonstrate the potential of epistemic interaction to significantly advance human-computer interaction by leveraging intuitive human communication strategies to inform system design and functionality, offering a novel pathway for enriching user-system engagements.
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.
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
Sleeping barber
1. 1 | P a g e 6
CA670 Concurrent Programming
Name Archana Kalapgar
Student Number 19210184
Programme MCM (Cloud)
Module Code CA670
Assignment Title Assignment One - Java Threads
Submission date 17-March-2020
Module coordinator David Sinclair
I declare that this material, which I now submit for assessment, is entirely my work and has
not been taken from the work of others, save and to the extent that such work has been cited
and acknowledged within the text of my work. I understand that plagiarism, collusion, and
copying are grave and serious offences in the university and accept the penalties that would be
imposed should I engage in plagiarism, collusion or copying. I have read and understood the
Assignment Regulations set out in the module documentation. I have identified and included
the source of all facts, ideas, opinions, and viewpoints of others in the assignment references.
Direct quotations from books, journal articles, internet sources, module text, or any other
source whatsoever are acknowledged, and the source cited are identified in the assignment
references. This assignment, or any part of it, has not been previously submitted by me or any
other person for assessment on this or any other course of study.
I have read and understood the referencing guidelines found recommended in the assignment
guidelines.
Name: Archana Kalapgar
Date: 17-March-2020
2. 2 | P a g e 6
Assignment One - Java Threads
Problem Statement:
We need to develop a multi-thread based Java program for a small barbershop that has two
doors, an entrance and an exit. Inside is a set of M barbers who spends all their lives serving
customers, one at a time. Each barber has a chair in which the customer sits when they are
getting their hair cut. When there are no customers in the shop waiting for their hair to be cut,
a barber sleeps in his chair. Customer arrives at random intervals, with mean mc and standard
deviation sdc. If a customer arrives and finds the barber asleep, he awakens the barber, sits in
the barber’s chair and sleeps while his hair is being cut. The time taken to cut a customer's hair
has a mean mh and standard deviation sdh. If a customer arrives and all the barbers are busy
cutting hair, the customer goes asleep in one of the N waiting chairs. When the barber finishes
cutting a customer’s hair, he awakens the customer and holds the exit door open for him. If
there are any waiting customers, he awakens one and waits for the customer to sit in the barber's
chair, otherwise, he goes to sleep.
The application must be:
• correct,
• fair,
• mutual exclusive,
• have no deadlock, and
• not have any individual thread "starved".
The application should be efficient concerning all actors.
Design of the application:
I developed a multi-threading Java application which is capable of running on a multiple-core
system. This application is capable of handling (n) number of barber and (m) number of
customers. It is also possible to increase the number of barber and customers accordingly.
Technologies Used:
1. Java for Multithreading
Java application consists of one package and four different classes. Below table
Represents the structure of the application.
Package Class
threading.practice SleepingBarber
Barber
Customer
BarberShop
3. 3 | P a g e 6
A brief description of each class is given below[1]:
1. SleepingBarber: This is the main class of application. This class is written explicitly
to take user input of the number of barber/s (barberCount), the number of customer/s
(customerCount), Mean (mean1), Standard Deviation (std1) for the duration of time
taken to cut a customer/s hair. Customer/s arrives at random intervals with runtime
mean (mean2) and standard deviation (std2). Barbershop has the number of waiting
chairs for the customer, which is also taken from the user (nChairs). All the methods
are made dynamic because they can be called creating the instance of the class where
it resides. A new object of the shop is created in the main class. New barber object is
created passing (mean1), (std1), and the object shop() to it. New customer() object is
created, and the customer arrival rate is set randomly by gaussian formula.
2. Barber: This class implements the following methods: getId(), setId(),
getBarberCuttingDurationMean(), SetBarberCuttingDurationMean(),
SetBarberCuttingDurationStdDev(), SetBarberCuttingDurationStdDev(). The run
method will call cutHair() method of object shop.
3. Customer: This class implements the following methods: getName(), setName(). The
entry of customer is added one at a time due to synchronize method invoking add
method for object shop(). When you have a synchronized method, you are locking on
the instance of the enclosing class. The run method will call goForHairCut() method.
4. Barbershop: This is the important class of the application. This class implements the
following methods: getnChair(), setnChair(). We create a linked list for the waiting
chair to preserve the order of insertion of the incoming customer. We pass (mean1) and
(std1) to getInterval() method and randomly generate duration of the barber to
cutHair(). Synchronize method makes sure to serve first customer thread at a time by
first barber thread. If there is no customer, the barber will wait for the customer. If there
are customer, then barber will take the first customer from the list. Add() method will
add customers in the list and synchronize method will make sure that first customer
thread sits on the waiting chair at a time. This class also creates tasks based on the
inputs sent by the constructor. It implements Runnable interface. If all the barber and
customer threads are busy and the waiting chair are occupied then the customer thread
exits from the loop.
Application design highlights [1] [2] [3] [4]:
1. Absence of Deadlock and Thread starvation: Inter thread communication is used to
prevent deadlocks. At a time, only one thread can access a synchronized method. As a
particular customer enters in the linked-list, a specific barber gets notify and gets the
lock. Barber finds the customer in the queue and performs haircut, completes haircut
and waits for lock again to perform same operations. This avoids deadlock. The
customers who come first are served first, this avoids starvation.
2. Correctness: Input is validated first then the barber and customer thread start to
execute. If all the barber and waiting chair are busy, customer exits from loop, else,
haircut is performed. Many other screenshots which confirm the correctness of the
application are submitted along with this report.
4. 4 | P a g e 6
3. Fairness: The barber thread, which is created first, gets the lock first. The customer
thread, which enters the linked list first is served first, which ensures the fairness of
application. Although the duration of haircut depends upon random variable based on
user input mean and standard deviation. Thus, the customer who started haircut first
may or may not end up finishing first.
4. Efficiency: The application works efficiently and serves all the customer/s in the list,
if number of customer/s (m) is double the number of barber/s (n) i.e (m=2*n) and
number of waiting chair is equal to the number of barber/s (n) i.e (waiting chair = n),
as shown in test cases [1 to 5].
A description of where a solution to the sleeping barber(s) problem is used
in practice:
1. Movie Ticket Booking: In an online movie ticket booking, the customer arrives in a
queue as first come first serve. A customer chooses a seat and that seat is asleep for 15
minutes until the payment confirmation. Once a booking is confirmed the customer
completes the task if the booking is failed then the seat is asleep for 15 minutes and no
customer can book that particular seat for the time interval. This is a synchronous
example of multithreading similar to sleeping barber problem.
2. AI Self Driving Car[4]: In an AI-based self-driving car, it is important to apply
sleeping barber problem. When a person is entering into the car, the car should wakeup
from sleep ready to function. If there is no person, a car should go back to sleep. This
is a real-life application of the sleeping barber problem.
Test Cases: In test cases [1 to 5], no customer exits from the loop and the barber completes
the haircut of all the customer threads. In test case [6], the barber was busy and the waiting
chairs were occupied, so some customer threads exit from the loop.
1. Barber: 5, Std1: 2, Mean1: 4, Customer: 10, Std2: 3, Mean2: 1, Waiting chair:
5, shown in the Image 1 -PASS.
2. Barber: 10, Std1: 3, Mean1: 1, Customer: 20, Std2: 2, Mean2: 4, Waiting chair:
10, shown in the Image 2- PASS.
3. Barber: 15, Std1: 4, Mean1: 4, Customer: 30, Std2: 4, Mean2: 4, Waiting chair:
15, screenshot submitted in the folder named “screenshots”- PASS.
4. Barber: 1000, Std1: 4, Mean1: 3, Customer: 2000, Std2: 3 Mean2: 4, Waiting
chair: 1000, screenshot submitted in the folder named “screenshots”- PASS.
5. Barber: 10000, Std1: 1, Mean1: 2, Customer: 20000, Std2: 3, Mean2: 4, Waiting
chair: 10000, screenshot submitted in the folder named “screenshots”- PASS.
6. Barber: 1, Std1: 7, Mean1: 9, Customer: 10, Std2: 3, Mean2: 1, Waiting chair:
5, screenshot submitted in the folder named “screenshots”- PASS.