Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use Java Thread to simulate money withdrawal

Shulou Source: shulou.com Published: 2022-06-01 04:25:33 09月30日 Update

This article mainly introduces the relevant knowledge of "how to use Java thread simulation to withdraw money". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "how to use Java thread simulation to withdraw money" can help you solve the problem.

Public class SynchronizedTTest {public static void main (String [] args) {Account account=new Account (100, "gifts"); Drawing you=new Drawing (account,80, "miserable"); Drawing wife=new Drawing (account,90, "happy"); you.start (); wife.start ();}} class Account {int money;String name;public Account (int money, String name) {this.money = money;this.name = name;}} class Drawing extends Thread {Account account / / the amount of money in the account (intended to pass into the Account object) the number of money withdrawn by int drawingMoney;// the name of the incoming thread public Drawing (Account account, int drawingMoney,String name) {super (name); this.account = account;this.drawingMoney = drawingMoney;} @ Override public void run () {account.money-=drawingMoney;packetMoney+=drawingMoney;System.out.println (this.getName () + "- > balance is" + account.money) System.out.println (this.getName () + "- > money in pocket is" + packetMoney);}} this is the end of the introduction to "how to use Java thread simulation to withdraw money". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Tags: Thread withdraw money knowledge pocket industry different practical miserable balance content name practicality actual object article method more case purpose knowledge point Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi OPPO Reno Shulou Tech Info Docker MySQL