用java编写一个多线程程序输出1+2+3+....+100;小弟初学多线程,有没有哪个大神能帮忙贴上代码谢啦
1个回答
展开全部
我用锁,用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"
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |