public class BankAccount { private int balance; public BankAccount(int initialBalance) { this.balance = initialBalance; } // Synchronized method to add money into the account public synchronized void deposit(int amount) { balance += amount; System.out.println("Deposited: " + amount + ", Balance: " + balance); } // Synchronized method to withdraw money from the account public synchronized void withdraw(int amount) { if (balance >= amount) { balance -= amount; System.out.println("Withdrawn: " + amount + ", Balance: " + balance); } else { System.out.println("Insufficient funds for withdrawal: " + amount); } } public static void main(String[] args) { BankAccount account = new BankAccount(1000); // Crearea și pornirea thread-urilor pentru depozit și retragere // Creating and starting the threads for deposit and withdrawal Thread depositThread = new Thread(() -> account.deposit(500)); Thread withdrawThread = new Thread(() -> account.withdraw(800)); depositThread.start(); withdrawThread.start(); } }