快速业务通道

Java?殻?仟蒙尢-迄?和? - 園殻秘壇利

作者 佚名技术 来源 NET编程 浏览 发布时间 2012-06-19

Java?殻?仟蒙尢-迄?和?

扮寂:2011-02-20 leizhimin

Java嶄響亟迄嗤倖俊笥java.util.concurrent.locks.ReadWriteLock?匆嗤醤悶議糞?ReentrantReadWriteLock??聾議API辛參臥心JavaAPI猟亀。

和中宸倖箭徨頁壓猟箭徨議児粥貧?繍噸宥迄個葎響亟迄?旺耶紗嬲薩噫駆臥儂議孔嬬?旗鷹泌和?

import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock; /** * Java?殻?迄 * * @author leizhimin 2009-11-5 10:57:29 */ public class Test {          public static void main(String[] args) {                  //幹秀旺窟恵諒議嬲薩                  MyCount myCount = new MyCount("95599200901215522", 10000);                  //幹秀匯倖迄斤?                  ReadWriteLock lock = new ReentrantReadWriteLock(false);                  //幹秀匯倖?殻学                  ExecutorService pool = Executors.newFixedThreadPool(2);                  //幹秀匯乂旺窟恵諒喘薩?匯倖佚喘触?贋議贋?函議函?挫犯綴亜                  User u1 = new User("嫖眉", myCount, -4000, lock, false);                  User u2 = new User("嫖眉麿漁", myCount, 6000, lock, false);                  User u3 = new User("嫖眉麿宮", myCount, -8000, lock, false);                  User u4 = new User("嫖眉", myCount, 800, lock, false);                  User u5 = new User("嫖眉麿漁", myCount, 0, lock, true);                  //壓?殻学嶄峇佩光倖喘薩議荷恬                  pool.execute(u1);                  pool.execute(u2);                  pool.execute(u3);                  pool.execute(u4);                  pool.execute(u5);                  //購液?殻学                  pool.shutdown();          } } /** * 佚喘触議喘薩 */ class User implements Runnable {          private String name; //喘薩兆           private MyCount myCount; //侭勣荷恬議嬲薩          private int iocash; //荷恬議署駆?輝隼嗤屎減岻蛍阻          private ReadWriteLock myLock; //峇佩荷恬侭俶議迄斤?          private boolean ischeck; //頁倦臥儂          User(String name, MyCount myCount, int iocash, ReadWriteLock myLock, boolean ischeck) {                  this.name = name;                  this.myCount = myCount;                  this.iocash = iocash;                  this.myLock = myLock;                  this.ischeck = ischeck;          }          public void run() {                  if 

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号