Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!