Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(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

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_2

Step: 3

blur-text-image_3

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

Database Driven Web Sites

Authors: Mike Morrison, Joline Morrison

1st Edition

061901556X, 978-0619015565

More Books

Students also viewed these Databases questions

Question

8. Explain the contact hypothesis.

Answered: 1 week ago

Question

7. Identify four antecedents that influence intercultural contact.

Answered: 1 week ago