当前位置: 首页 > news >正文

用cdr做网站设计尺寸要多少网页设计与网站建设步骤

用cdr做网站设计尺寸要多少,网页设计与网站建设步骤,泉州做网站qzxiaolv,做网站什么价位乒乓是一个经典示例#xff0c;其中2个玩家#xff08;或线程#xff09;访问共享资源–乒乓球桌并在彼此之间传递Ball#xff08;状态变量#xff09;。 使用任何共享资源#xff0c;除非我们同步访问#xff0c;否则线程可能会遇到潜在的死锁情况。 PingPong算法非常简… 乒乓是一个经典示例其中2个玩家或线程访问共享资源–乒乓球桌并在彼此之间传递Ball状态变量。 使用任何共享资源除非我们同步访问否则线程可能会遇到潜在的死锁情况。 PingPong算法非常简单 如果轮到我{ 更新下一轮 ping / pong-记录点击 通知其他线程 }其他{ 等待通知 } 让我们来看一个例子看看它是如何工作的 这是我们的Player类它实现Runnable并接受对共享资源和消息的访问 public class Player implements Runnable {PingPong myTable; Table where they playString myOpponent;public Player(String opponent, PingPong table) {myTable table;myOpponent opponent;}public void run() {while (myTable.hit(myOpponent));}} 其次我们看到PingPong表类该类具有一个同步方法hit无论是否轮到我都在其中进行检查。 如果轮到我了请记录ping并更新对手姓名的共享变量。 public class PingPong {state variable identifying whose turn it is.private String whoseTurn null;public synchronized boolean hit(String opponent) {String x Thread.currentThread().getName();if (x.compareTo(whoseTurn) 0) {System.out.println(PING! ( x ));whoseTurn opponent;notifyAll();} else {try { wait(2500); } catch (InterruptedException e) { }}}} 接下来我们开始游戏并使玩家开始 public class Game {public static void main(String args[]) {PingPong table new PingPong();Thread alice new Thread(new Player(bob, table));Thread bob new Thread(new Player(alice, table));alice.setName(alice);bob.setName(bob);alice.start(); alice starts playingbob.start(); bob starts playingtry {Wait 5 secondsThread.sleep(5000);} catch (InterruptedException e) {}table.hit(DONE); cause the players to quit their threads.try {Thread.sleep(100);} catch (InterruptedException e) {}}} 就是这样我们正在运行PingPong游戏。 在这种情况下我们看到了同步方法hit如何仅允许一个线程访问共享资源– itsTurn。 Akka STM提供了两个构造Refs和Agents。 引用事务引用提供对多个身份的协调同步访问。 代理提供对单个身份的非协调异步访问。 参考 在我们的例子中由于共享状态变量是单个标识因此引用的使用是过大的但是我们仍然会继续查看它们的用法。 public class PingPong {updates to Ref.View are synchronousRef.ViewString whoseTurn;public PingPong(Ref.ViewString player) {whoseTurn player;}public boolean hit(final String opponent) {final String x Thread.currentThread().getName();if (x.compareTo(whoseTurn.get()) 0) {System.out.println(PING! ( x ));whoseTurn.set(opponent);} else {try {wait(2500);} catch (Exception e) {}}}} 这里的关键是以下 同步关键字丢失 将状态变量定义为Ref //更新到Ref.View是同步的 Ref.View string其Turn; 调用更新Ref是协调和同步的 whoTurn.setopponent ; 因此当我们使用Ref保持状态时对Ref的访问会在事务中自动同步。 代理商 由于代理提供了不协调的异步访问因此使用代理进行状态操作将意味着我们需要等到所有更新都已应用到代理之后。 代理为获取提供非阻塞访问。 public class PingPong {AgentString whoseTurn;public PingPong(AgentString player) {whoseTurn player;}public boolean hit(final String opponent) {final String x Thread.currentThread().getName();wait till all the messages are processed to make you get the correct value, as updated to Agents areasyncString result whoseTurn.await(new Timeout(5, SECONDS));if (x.compareTo(result) 0) {System.out.println(PING! ( x ));whoseTurn.send(opponent);} else {try {wait(2500);} catch (Exception e) {}}return true; keep playing.}} 这里的关键是以下 同步关键字丢失 将状态变量定义为Agent //更新到Ref.View是同步的 Agent string其Turnn; 等待对代理的更新因为对代理的更新是异步的 字符串结果 whoTurn.awaitnew Timeout5SECONDS; 调用更新Ref是协调和同步的 whoTurn.sendopponent ; 这些示例中引用的所有代码都可以在– https://github.com/write2munish/Akka-Essentials/tree/master/AkkaSTMExample/src/main/java/org/akka/essentials/stm/pingpong中找到 示例1 –用于基于普通线程的同步 示例2 –使用Refs进行同步 示例3 –使用代理进行同步 参考在Akka Essentials博客上与我们的JCG合作伙伴 Munish K Gupta 一起使用STM – Refs和Agents打乒乓球。 翻译自: https://www.javacodegeeks.com/2012/05/akka-stm-playing-pingpong-with-stm-refs.html
http://www.pierceye.com/news/42476/

相关文章:

  • 专业的广州商城网站建设腾讯云服务器做网站
  • wordpress的站点是什么昆明网站建设-中国互联
  • 潍坊网站建设推荐广告公司是做什么的
  • 营销网站设计公司国外专门做童装的网站
  • 海安网站设计公司企业服务工作站
  • 自己的网站怎么做的注册餐饮公司需要什么条件
  • 铁岭建设银行网站网站开发系统设计
  • 如何组建网站开发团队阿里云服务器创建网站
  • 咚咚抢网站怎么做的分类信息网站建设计划
  • 白云区手机版网站建设苏宿工业园区网站建设成功案例
  • 做网站备案时间wordpress前台修改
  • 怎样建设网站空间企业网站的制作原则
  • 怎么把网站做成自适应内江建设局网站
  • 惠州网站制作定制青县建设银行网站
  • 淘宝客自建网站沈阳模板建站方案
  • 网站建站的一般步骤福州大型网站设计公司
  • 做网站用属于前端wordpress类似于
  • 西安网站建站品牌佛山学校网站建设
  • 用php做网站流程人人秀h5制作教程
  • 做一个网站花费多少钱深圳企业网站备案
  • 企业门户网站功能描述wordpress 媒体备份
  • 网站建设需要那些人才网络营销网站 功能
  • 做爰在线网站wordpress iframe插件
  • 江苏省建设工程交易中心网站什么网比较好
  • 如何修改网站抓取内容腾讯企业邮箱免费登录入口
  • 网站建设论文深圳软件app开发公司
  • 找人做彩票网站多少钱酒店网站开发协议
  • 夹江企业网站建设报价百度移动应用
  • 重庆一次可以备案多少个网站wordpress一键建站
  • 深圳定制专业网站工厂网站建设公司