Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Assume now that we declare printTranscript ( ) as synchronized, and do not change anything else. Is the above code prone to deadlocks? Explain why
Assume now that we declare printTranscript as synchronized, and do
not change anything else. Is the above code prone to deadlocks? Explain why or
why not.
Report your answer in the following format.
Qc Answer:
Qc Explanation:
public class Student
public String id;
private String name;
private volatile boolean active;
private ArrayList exams;
public StudentString id String name
this.id id;
this.name name;
this.active false;
this.exams new ArrayList;
public synchronized String getName
return this.name;
public synchronized void registerModule module
module.addStudentthisid;
this.active true;
public synchronized void addExamExam exam
this.exams.addexam;
public synchronized ArrayList getTranscript
return new ArrayListthisexams;
public void printTranscript
if this.active
System.out.printlncurrently inactive;
synchronizedthis
System.out.printlnStudent this.name;
for Exam e: this.exams
System.out.printlnetoString;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started