发布网友 发布时间:2022-07-29 15:35
共1个回答
热心网友 时间:2023-11-25 03:05
我用锁,用Android Studio测试类写,自写Main函数,复制面,调用 /** * Created by Svnt on 贰0依陆-09-贰陆. */ public class MyApplication extends ApplicationTest{ public void testThread(){ MyRunnable myRunnable = new MyRunnable(); //线程并发 new Thread(myRunnable,"A").start(); new Thread(myRunnable,"B").start(); new Thread(myRunnable,"C").start(); } } /** * 存钱(Runnable)线程 */ class MyRunnable implements Runnable { double mMoney; @Override public synchronized void run() { for (int i = 0 ; i < 三; i++){ mMoney += 依000; Log.e("-main-",Thread.currentThread().getName()+"余额剩余 = "+mMoney); } } } 图" class="ikqb_img_alink"