- Replace DemoFactory with DemoApplication to centralize system setup, execution, and shutdown - Move ExecutorService and ScheduledExecutorService lifecycle management into application layer - Ensure proper shutdown sequence for worker and monitoring threads - Simplify Main class to a minimal entry-point wrapper - Improve clarity of execution flow: build → run → shutdown - Prevent resource leakage by explicitly awaiting termination of thread pools
53 lines
1.1 KiB
Java
53 lines
1.1 KiB
Java
package dev.banking.model;
|
|
|
|
public class BankAccount {
|
|
|
|
private final int accountId;
|
|
private long balance;
|
|
|
|
/*
|
|
* Students may introduce additional fields
|
|
* if required by their synchronization strategy.
|
|
*/
|
|
|
|
public BankAccount(int accountId, long initialBalance) {
|
|
this.accountId = accountId;
|
|
this.balance = initialBalance;
|
|
}
|
|
|
|
public int getAccountId() {
|
|
return accountId;
|
|
}
|
|
|
|
/*
|
|
* TODO
|
|
* Implement a thread-safe balance reader.
|
|
*/
|
|
public long getBalance() {
|
|
throw new UnsupportedOperationException();
|
|
}
|
|
|
|
/*
|
|
* TODO
|
|
* Implement a thread-safe deposit operation.
|
|
*/
|
|
public void deposit(long amount) {
|
|
throw new UnsupportedOperationException();
|
|
}
|
|
|
|
/*
|
|
* TODO
|
|
* Implement a thread-safe withdrawal operation.
|
|
*/
|
|
public void withdraw(long amount) {
|
|
throw new UnsupportedOperationException();
|
|
}
|
|
|
|
/*
|
|
* TODO
|
|
* Implement an atomic and deadlock-free transfer.
|
|
*/
|
|
public void transfer(BankAccount target, long amount) {
|
|
throw new UnsupportedOperationException();
|
|
}
|
|
} |