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

设计网站横幅域名解析后怎么做网站

设计网站横幅,域名解析后怎么做网站,网站开发研究生,pacdora 设计网文章目录 1. 定义2. 实现保护性暂停模式3. Join原理4. 保护性暂停模式的扩展 1. 定义 即Guarded Suspension#xff0c;用在一个线程等待另一个线程的执行结果。 有一个结果需要从一个线程传递给另一个线程#xff0c;让他们关联到同一个GuarderObject#xff08;这就是保… 文章目录 1. 定义2. 实现保护性暂停模式3. Join原理4. 保护性暂停模式的扩展 1. 定义 即Guarded Suspension用在一个线程等待另一个线程的执行结果。 有一个结果需要从一个线程传递给另一个线程让他们关联到同一个GuarderObject这就是保护性暂停模式是两个线程之间交换结果的模式如果有结果不断从一个线程到另一个线程可以使用消息队列这个是生产者-消费者模式JDK中Join实现Futrue的实现采用的就是此模式因为要等待另一方的结果因此归类到同步模式 2. 实现保护性暂停模式 实现这个模式的关键是GuardedObjectresponse属性是用来保存中间结果。所以我们使用wait-notify来实现保护性暂停模式。 实现保护对象 class GuardedObject{private Object response;//获取结果public Object get() {synchronized (this){while(responsenull){try {this.wait();} catch (InterruptedException e) {e.printStackTrace();}}return response;}}public void complete(Object response){synchronized (this){this.responseresponse;this.notify();}} }案例场景线程1等待线程二的下载结果 public class jvm {public static ListString downLoad() throws IOException {HttpURLConnection connection (HttpURLConnection) new URL(https://www.baidu.com/).openConnection();ListString listnew ArrayList();try(BufferedReader readernew BufferedReader(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8))){String line;while((line reader.readLine())!null){list.add(line);}}return list;}public static void main(String[] args) {GuardedObject guardedObjectnew GuardedObject();new Thread(()-{log.debug(等待结果);ListString list (ListString) guardedObject.get();log.debug(结果大小,[{}],list.size());},线程1).start();new Thread(()-{log.debug(执行下载);try {ListString listdownLoad();guardedObject.complete(list);} catch (IOException e) {e.printStackTrace();}},线程2).start();} }3. Join原理 Join底层原理就是基于这种保护性暂停的模式首先我们来看看Join的底层源码 public final synchronized void join(long millis)throws InterruptedException {//获得系统当前的时间戳long base System.currentTimeMillis();//定义当前时间戳为0long now 0;if (millis 0) {throw new IllegalArgumentException(timeout value is negative);}//如果传入的等待时间为0if (millis 0) {//如果线程是存活的就一直等待调用wait(0)while (isAlive()) {wait(0);}} else {while (isAlive()) {long delay millis - now;if (delay 0) {break;}wait(delay);now System.currentTimeMillis() - base;}}}public final synchronized void join(long millis, int nanos)throws InterruptedException {if (millis 0) {throw new IllegalArgumentException(timeout value is negative);}if (nanos 0 || nanos 999999) {throw new IllegalArgumentException(nanosecond timeout value out of range);}if (nanos 500000 || (nanos ! 0 millis 0)) {millis;}join(millis);}public final void join() throws InterruptedException {join(0);}从源码可以看出join的底层就是使用wait机制实现的。 4. 保护性暂停模式的扩展 途中Futures就好比居民楼的一层信箱每个信箱都有自己的编号左侧的t0t2t4就好比等待邮件的居民等待结果的线程右侧t1t3t5就好比邮递员。如果需要在多个类之间使用GuardedObject对象作为参数传递不是很方便因此设计一个用来解耦的中间类这样不仅仅能够解藕结果等待者和结果生产者还能支持多个任务的管理。 改造GuardedObject类 class GuardedObject{private Object response;private int id;public GuardedObject(){}public GuardedObject(int id){this.idid;}public int getId(){return id;}//获取结果public Object get() {synchronized (this){while(responsenull){try {this.wait();} catch (InterruptedException e) {e.printStackTrace();}}return response;}}public void complete(Object response){synchronized (this){this.responseresponse;this.notify();}} }构造解耦类 class Boxes{private static MapInteger,GuardedObject boxnew ConcurrentHashMap();//产生一个唯一的idpublic static int id1;private static synchronized int increment(){return id;}public static GuardedObject getGuardedObject(int id){return box.remove(id);}public static GuardedObject creatGuardedObject(){GuardedObject guardedObjectnew GuardedObject(increment());box.put(guardedObject.getId(),guardedObject);return guardedObject;}public static SetInteger getIds(){return box.keySet();}}创造等待线程和生产线程 Slf4j class PostMan extends Thread{private int id;private String mail_contex;//邮递员创建信件public PostMan(int id,String mail_contex){this.idid;this.mail_contexmail_contex;}Overridepublic void run(){GuardedObject guardedObjectBoxes.getGuardedObject(id);log.debug(送信-{},内容-{},id,mail_contex);guardedObject.complete(mail_contex);} } class Boxes{private static MapInteger,GuardedObject boxnew Hashtable();//产生一个唯一的idpublic static int id1;private static synchronized int increment(){return id;}public static GuardedObject getGuardedObject(int id){return box.remove(id);}public static GuardedObject creatGuardedObject(){GuardedObject guardedObjectnew GuardedObject(increment());box.put(guardedObject.getId(),guardedObject);return guardedObject;}public static SetInteger getIds(){return box.keySet();}}测试 public class jvm {public static void main(String[] args) throws InterruptedException {for (int i 0; i 3; i) {new Poeple().start();}Thread.sleep(1000);for (Integer id : Boxes.getIds()) {new PostMan(id, 内容 id).start();}} }
http://www.pierceye.com/news/275645/

相关文章:

  • 重庆营销网站建设平台怎么添加wordpress模板
  • 网站赚取广告费深圳个人外贸网站建
  • 在线销售型的网站巢湖城市建设投资有限公司网站
  • 苏州高端网站建设设计程序源代码网站
  • 基本原理网站建设文档怎么做网站链接
  • 网站建设出售门户网站有哪些推广分类
  • 企业网站制作一般多少钱做ppt的兼职网站有哪些
  • 分公司可以建设网站淘宝联盟怎么推广
  • 苏州网站设计哪家公司好童程童美编程地址在哪里
  • 软文营销的成功案例百度优化怎么做
  • 公司网站开发怎么收费优化方案英语必修三
  • 网站改版阿里云怎么做网站301定向温州网站运营
  • 免费做简历网站有哪些网站建设与网页制作招聘
  • 怎么到国外网站去接模具订单做潍坊微信网站开发
  • 做船公司网站青海公司网站建设哪家好
  • 制作网站公司合同注意事项沈阳高端网站
  • 企业网站备案时间网站建设的服务和质量
  • 提供视频下载的网站建网站开发费用
  • 深圳电商网站开发公司上海公司排名
  • 网站建设时间规划表学校网站网页制作
  • 龙岗建网站工信部网站备案进度查询
  • 个人网站域名名字wordpress文章页获取目录名称
  • 新公司做网站有效果吗seo推广营销公司
  • 做网络推广要做网站吗网站建设首页模板
  • 陕西网站设计高端网站设计公司名单
  • 建设网站企业公众号wordpress
  • 个人的小说网站如何做北京网站制作收费标准
  • 做海报的素材哪个网站微信如何创建自己的公众号
  • 怎样进行网站后台管理网站内容做淘宝店铺链接影响排名吗
  • 重庆网站编辑职业学校苏州企业网站制作开发