Question
(a) Write a serializable Car class, a car object has registration, make, year and price. (b) Implement a Java code to implement Bank Transfer method
(a) Write a serializable Car class, a car object has registration, make, year and price.
(b) Implement a Java code to implement Bank Transfer method that ensures thread safe and lock free, the method accepts two account and amount to be transferred.
(c) The class Book, listed below, is thread safe but may deadlock. Explain why and re-write it so that deadlocks cannot occur.
class Book{ private String title;
private Lock lock = new ReentrantLock();
Book(String t){title = t;}
String title(){ lock.lock();
try{ return title;}
finally{lock.unlock();} }
void set(String nt){ lock.lock();
try{title = nt;}
finally{lock.unlock();} }
public boolean equals(Object p){ lock.lock();
try{ Book b = (Book)p; b.lock.lock();
try{ return(title.equals(b.title));}
finally{b.lock.unlock();} }
finally{lock.unlock();} }}
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