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

门户网站架构网站描述代码

门户网站架构,网站描述代码,长沙网站列表,农机网站模版目录 一、截图示例二、代码示例2.1 测试代码2.2 接口代码 一、截图示例 二、代码示例 2.1 测试代码 package com.learning.countdownlatch;import lombok.extern.slf4j.Slf4j; import org.springframework.web.client.RestTemplate;import java.util.Arrays; import java.uti…

目录

        • 一、截图示例
        • 二、代码示例
          • 2.1 测试代码
          • 2.2 接口代码

一、截图示例

在这里插入图片描述
在这里插入图片描述

二、代码示例
2.1 测试代码
package com.learning.countdownlatch;import lombok.extern.slf4j.Slf4j;
import org.springframework.web.client.RestTemplate;import java.util.Arrays;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;/*** @Author wangyouhui* @Description 异步查询信息**/
@Slf4j
public class Learning_03 {public static void main(String[] args) {test1();test2();}private static void test1() {System.out.println("查询信息开始");long begin = System.currentTimeMillis();log.info("开始时间: {}", begin);RestTemplate restTemplate = new RestTemplate();long start = System.currentTimeMillis();Map<String, Object> map = restTemplate.getForObject("http://127.0.0.1:8080/info/order/{1}", Map.class, 1);log.info("订单信息: {}, 耗时: {}", map, System.currentTimeMillis() - start);start = System.currentTimeMillis();map = restTemplate.getForObject("http://127.0.0.1:8080/info/product/{1}", Map.class, 1);log.info("产品1信息: {}, 耗时: {}", map, System.currentTimeMillis() - start);start = System.currentTimeMillis();map = restTemplate.getForObject("http://127.0.0.1:8080/info/product/{1}", Map.class, 2);log.info("产品2信息: {}, 耗时: {}", map, System.currentTimeMillis() - start);start = System.currentTimeMillis();map = restTemplate.getForObject("http://127.0.0.1:8080/info/package/{1}", Map.class, 1);log.info("快递信息: {}, 耗时: {}", map, System.currentTimeMillis() - start);long end = System.currentTimeMillis();log.info("结束时间: {}", end);log.info("查询信息结束, 总耗时: {}", end-begin);}private static void test2() {System.out.println("查询信息开始");long begin = System.currentTimeMillis();log.info("开始时间: {}", begin);CountDownLatch countDownLatch = new CountDownLatch(4);ExecutorService executorService = Executors.newCachedThreadPool();RestTemplate restTemplate = new RestTemplate();executorService.submit(()->{long start = System.currentTimeMillis();Map<String, Object> map = restTemplate.getForObject("http://127.0.0.1:8080/info/order/{1}", Map.class, 1);log.info("订单信息: {}, 耗时: {}", map, System.currentTimeMillis() - start);countDownLatch.countDown();});executorService.submit(()->{long start = System.currentTimeMillis();Map<String, Object> map = restTemplate.getForObject("http://127.0.0.1:8080/info/product/{1}", Map.class, 1);log.info("产品1信息: {}, 耗时: {}", map, System.currentTimeMillis() - start);countDownLatch.countDown();});executorService.submit(()->{long start = System.currentTimeMillis();Map<String, Object> map = restTemplate.getForObject("http://127.0.0.1:8080/info/product/{1}", Map.class, 2);log.info("产品2信息: {}, 耗时: {}", map, System.currentTimeMillis() - start);countDownLatch.countDown();});executorService.submit(()->{long start = System.currentTimeMillis();Map<String, Object> map = restTemplate.getForObject("http://127.0.0.1:8080/info/package/{1}", Map.class, 1);log.info("快递信息: {}, 耗时: {}", map, System.currentTimeMillis() - start);countDownLatch.countDown();});// 主线程等待try{countDownLatch.await();}catch (InterruptedException e){e.printStackTrace();}executorService.shutdown();long end = System.currentTimeMillis();log.info("结束时间: {}", end);log.info("查询信息结束, 总耗时: {}", end-begin);}
}
2.2 接口代码
package com.learning.controller;import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;import java.util.HashMap;
import java.util.Map;
import java.util.Random;/*** @Author wangyouhui* @Description TODO**/
@RestController
@RequestMapping("info")
@Slf4j
public class InfoController {@GetMapping("/order/{id}")public Map<String, Object> orderDetail(@PathVariable Long id){log.info("开始查找订单: {}", id);try {Random random = new Random();Thread.sleep(2000 + random.nextInt(2000));} catch (InterruptedException e) {e.printStackTrace();}Map<String, Object> result = new HashMap<>();result.put("id", id);result.put("total", 1300);log.info("查找订单结束: {}", id);return result;}@GetMapping("/product/{id}")public Map<String, Object> productDetail(@PathVariable Long id){log.info("开始查找产品: {}", id);try {Random random = new Random();Thread.sleep(500 + random.nextInt(2000));} catch (InterruptedException e) {e.printStackTrace();}Map<String, Object> result = new HashMap<>();if(id == 1){result.put("id", id);result.put("price", 300);result.put("name", "小米耳机");}else{result.put("id", id);result.put("price", 1000);result.put("name", "三星硬盘");}log.info("开始查找产品: {}", id);return result;}@GetMapping("/package/{id}")public Map<String, Object> packageDetail(@PathVariable Long id){log.info("开始查找快递: {}", id);try {Random random = new Random();Thread.sleep(3000 + random.nextInt(1000));} catch (InterruptedException e) {e.printStackTrace();}Map<String, Object> result = new HashMap<>();result.put("id", id);result.put("name", "中通快递");result.put("id", id);log.info("开始查找快递: {}", id);return result;}
}
http://www.yayakq.cn/news/322458/

相关文章:

  • 企业网站设计过程中必须重视的问题之一海外流量渠道
  • 成都高档网站建设免费游戏网站建设
  • 百色建设局网站17网站一起做 佛山
  • 网站建设信息推荐四大免费网站
  • 建设工程设计备案网站基于html5开发的网站开发
  • h5免费制作平台哪个好企业网站优化是什么
  • 深圳建设厅官方网站建设淘宝网站的目的
  • 淘宝联盟怎么自己做网站网站开发人员薪酬
  • 端子网站建设国外企业建站
  • 广告设计哪个网站好东莞招投标服务中心
  • 网络营销策划书范文商丘网站优化公司
  • 一般网站的流量是多少上海建站网络公司
  • 有哪些好的做问卷调查的网站怀化市住房建设局网站
  • 网站设计服务费一般多少钱网站需要哪些备案
  • 涟源网站建设营销型网站的建设要求都有什么影响
  • 酒泉网站建设推广拘束 wordpress
  • 二手手机回收网站开发h5网站模板开发
  • 自建房外观设计网站推荐广东的互联网公司有哪些
  • 园林景观 网站建设百度站长工具数据提交
  • 免费海报素材网站大全长春网站营销
  • 个人网站效果图电商网页设计的主要内容
  • 做服装网站需要什么条件手机网站 微信平台
  • 对网站开发与管理的分析湖南建设网站
  • 品牌宣传型网站网站开发 图片库
  • 论坛网站搭建中国去中心化搜索引擎
  • 福建建设中心网站男女激烈做羞羞事网站网站韩剧
  • 温州外贸网站建设公司wordpress命令安装
  • 管理学习网站东营市建设工程网官网
  • 江苏网站建设费用wordpress使用jquery
  • 做的网站需要买什么系统服务器注册建筑公司