Answered step by step
Verified Expert Solution
Link Copied!

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.
Q4c Answer:
Q4c Explanation:
public class Student {
public String id;
private String name;
private volatile boolean active;
private ArrayList exams;
public Student(String 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 register(Module module){
module.addStudent(this.id);
this.active = true;
}
public synchronized void addExam(Exam exam){
this.exams.add(exam);
}
public synchronized ArrayList getTranscript(){
return new ArrayList(this.exams);
}
public void printTranscript(){
if (! this.active){
System.out.println("(currently inactive)");
}
synchronized(this){
System.out.println("Student "+ this.name);
for (Exam e: this.exams){
System.out.println(e.toString());
}
}
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Semantics In Databases Second International Workshop Dagstuhl Castle Germany January 2001 Revised Papers Lncs 2582

Authors: Leopoldo Bertossi ,Gyula O.H. Katona ,Klaus-Dieter Schewe ,Bernhard Thalheim

2003rd Edition

3540009574, 978-3540009573

More Books

Students also viewed these Databases questions