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

北京十大网站建设公司专门做设计文案的网站

北京十大网站建设公司,专门做设计文案的网站,wordpress采集文章,家装在线设计平台首先要明确一点#xff0c;同步请求和异步请求对于客户端用户来讲是一样的#xff0c;都是需客户端等待返回结果。不同之处在于请求到达服务器之后的处理方式#xff0c;下面用两张图解释一下同步请求和异步请求在服务端处理方式的不同#xff1a;同步请求异步请求两个流程…首先要明确一点同步请求和异步请求对于客户端用户来讲是一样的都是需客户端等待返回结果。不同之处在于请求到达服务器之后的处理方式下面用两张图解释一下同步请求和异步请求在服务端处理方式的不同同步请求异步请求两个流程中客户端对Web容器的请求都是同步的。因为它们在请求客户端时都处于阻塞等待状态并没有进行异步处理。在Web容器部分第一个流程采用同步请求第二个流程采用异步回调的形式。通过异步处理可以先释放容器分配给请求的线程与相关资源减轻系统负担从而增加了服务器对客户端请求的吞吐量。但并发请求量较大时通常会通过负载均衡的方案来解决而不是异步。使用AsyncContext执行异步请求package com.example.async;import java.io.IOException; import javax.servlet.AsyncContext; import javax.servlet.AsyncEvent; import javax.servlet.AsyncListener; import javax.servlet.http.HttpServletRequest; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController;RestController public class AsyncContextController {GetMapping(/asyncContext)ResponseBodypublic String asyncTask(HttpServletRequest request) {AsyncContext asyncContext request.startAsync();asyncContext.addListener(new AsyncListener() {Overridepublic void onTimeout(AsyncEvent event) throws IOException {System.out.println(处理超时了...);}Overridepublic void onStartAsync(AsyncEvent event) throws IOException {System.out.println(线程开始执行);}Overridepublic void onError(AsyncEvent event) throws IOException {System.out.println(执行过程中发生错误 event.getThrowable().getMessage());}Overridepublic void onComplete(AsyncEvent event) throws IOException {System.out.println(执行完成释放资源);}});asyncContext.setTimeout(6000);asyncContext.start(new Runnable() {Overridepublic void run() {try {Thread.sleep(5000);System.out.println(内部线程 Thread.currentThread().getName());asyncContext.getResponse().getWriter().println(async processing);} catch (Exception e) {System.out.println(异步处理发生异常 e.getMessage());}asyncContext.complete(); // 异步请求完成通知整个请求完成}});System.out.println(主线程 Thread.currentThread().getName()); return OK;} }使用Callable执行异步请求package com.example.async;import java.util.concurrent.Callable; import java.util.concurrent.TimeUnit; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController;RestController public class CallableController {GetMapping(path /callable)ResponseBodypublic CallableString asyncRequest() {return () - {TimeUnit.SECONDS.sleep(10);return OK;};} }使用WebAsyncTask执行异步请求package com.example.async;import java.util.concurrent.Callable; import java.util.concurrent.TimeUnit; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.context.request.async.WebAsyncTask;RestController public class WebAsyncTaskController {GetMapping(/webAsyncTask)ResponseBodypublic WebAsyncTaskString asyncTask() {WebAsyncTaskString webAsyncTask new WebAsyncTaskString(1000l * 10, new CallableString() {Overridepublic String call() throws Exception {TimeUnit.SECONDS.sleep(5);return OK;}});webAsyncTask.onCompletion(new Runnable() {Overridepublic void run() {System.out.println(调用完成);}});webAsyncTask.onTimeout(new CallableString() {Overridepublic String call() throws Exception {return Time Out;}});return webAsyncTask;} } 使用DeferredResult执行异步请求package com.example.async;import java.util.concurrent.TimeUnit; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.context.request.async.DeferredResult;RestController public class DeferredResultController {GetMapping(path /deferredResult)ResponseBodypublic DeferredResultString asyncRequest() {DeferredResultString deferredResult new DeferredResult(1000L * 5, 失败);deferredResult.onTimeout(() - {System.out.println(调用超时);deferredResult.setResult(调用超时);});deferredResult.onCompletion(() - {System.out.println(调用完成);});new Thread(() - {try {TimeUnit.SECONDS.sleep(10);deferredResult.setResult(OK);} catch (Exception e) {e.printStackTrace();}}).start();return deferredResult;} }另外Spring Boot中使用注解Async处理异步任务Async注解的异步操作和上文所诉的四种异步请求不同之处在于使用Async处理异步任务时没有异步回调响应客户端的流程使用EnableAsync开启Asyncpackage com.example;import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.scheduling.annotation.EnableAsync;EnableAsync SpringBootApplication public class ExampleApplication {public static void main(String[] args) {SpringApplication.run(ExampleApplication.class, args);}}如果将Async加在Controller上或是 Controller 的方法上package com.example.async;import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Async; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController;RestController public class AsyncController {Autowiredprivate TestService testService;GetMapping(/async)ResponseBodyAsyncpublic String asyncTask() {testService.doSomeThing();System.out.println(处理完成);return OK;} }控制器立即会给客户端空响应但是控制器方法依旧执行如果将Async加在Service上或是 Service 的方法上package com.example.async;import java.util.concurrent.TimeUnit; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service;Service public class TestService {Asyncpublic void doSomeThing() {try {TimeUnit.SECONDS.sleep(5);} catch (InterruptedException e) {e.printStackTrace();}} }控制器不再等待Service方法执行完毕就响应客户端
文章转载自:
http://www.morning.sjgsh.cn.gov.cn.sjgsh.cn
http://www.morning.qkrgk.cn.gov.cn.qkrgk.cn
http://www.morning.rlzxr.cn.gov.cn.rlzxr.cn
http://www.morning.yrddl.cn.gov.cn.yrddl.cn
http://www.morning.ryglh.cn.gov.cn.ryglh.cn
http://www.morning.zyslyq.cn.gov.cn.zyslyq.cn
http://www.morning.fpkdd.cn.gov.cn.fpkdd.cn
http://www.morning.qhrdx.cn.gov.cn.qhrdx.cn
http://www.morning.jgrjj.cn.gov.cn.jgrjj.cn
http://www.morning.lbcbq.cn.gov.cn.lbcbq.cn
http://www.morning.zcfmb.cn.gov.cn.zcfmb.cn
http://www.morning.cpmfp.cn.gov.cn.cpmfp.cn
http://www.morning.zqkms.cn.gov.cn.zqkms.cn
http://www.morning.jbpdk.cn.gov.cn.jbpdk.cn
http://www.morning.kzrbn.cn.gov.cn.kzrbn.cn
http://www.morning.hcrxn.cn.gov.cn.hcrxn.cn
http://www.morning.ktblf.cn.gov.cn.ktblf.cn
http://www.morning.rhmt.cn.gov.cn.rhmt.cn
http://www.morning.ftwlay.cn.gov.cn.ftwlay.cn
http://www.morning.hympq.cn.gov.cn.hympq.cn
http://www.morning.bnfjh.cn.gov.cn.bnfjh.cn
http://www.morning.kpcjl.cn.gov.cn.kpcjl.cn
http://www.morning.rfhmb.cn.gov.cn.rfhmb.cn
http://www.morning.ypklb.cn.gov.cn.ypklb.cn
http://www.morning.kjcfz.cn.gov.cn.kjcfz.cn
http://www.morning.xq3nk42mvv.cn.gov.cn.xq3nk42mvv.cn
http://www.morning.mksny.cn.gov.cn.mksny.cn
http://www.morning.rstrc.cn.gov.cn.rstrc.cn
http://www.morning.cwjsz.cn.gov.cn.cwjsz.cn
http://www.morning.gnfkl.cn.gov.cn.gnfkl.cn
http://www.morning.synlt.cn.gov.cn.synlt.cn
http://www.morning.rfwgg.cn.gov.cn.rfwgg.cn
http://www.morning.rxtxf.cn.gov.cn.rxtxf.cn
http://www.morning.pcqxr.cn.gov.cn.pcqxr.cn
http://www.morning.drfrm.cn.gov.cn.drfrm.cn
http://www.morning.rjmb.cn.gov.cn.rjmb.cn
http://www.morning.hyjpl.cn.gov.cn.hyjpl.cn
http://www.morning.mtsck.cn.gov.cn.mtsck.cn
http://www.morning.xqjh.cn.gov.cn.xqjh.cn
http://www.morning.kbynw.cn.gov.cn.kbynw.cn
http://www.morning.dmtld.cn.gov.cn.dmtld.cn
http://www.morning.tpyjr.cn.gov.cn.tpyjr.cn
http://www.morning.lpppg.cn.gov.cn.lpppg.cn
http://www.morning.tbbxn.cn.gov.cn.tbbxn.cn
http://www.morning.dtgjt.cn.gov.cn.dtgjt.cn
http://www.morning.swkzk.cn.gov.cn.swkzk.cn
http://www.morning.wbllx.cn.gov.cn.wbllx.cn
http://www.morning.cknws.cn.gov.cn.cknws.cn
http://www.morning.kscwt.cn.gov.cn.kscwt.cn
http://www.morning.yxbrn.cn.gov.cn.yxbrn.cn
http://www.morning.c7500.cn.gov.cn.c7500.cn
http://www.morning.bydpr.cn.gov.cn.bydpr.cn
http://www.morning.tyklz.cn.gov.cn.tyklz.cn
http://www.morning.xflzm.cn.gov.cn.xflzm.cn
http://www.morning.qggxt.cn.gov.cn.qggxt.cn
http://www.morning.gmnmh.cn.gov.cn.gmnmh.cn
http://www.morning.lnrr.cn.gov.cn.lnrr.cn
http://www.morning.rtryr.cn.gov.cn.rtryr.cn
http://www.morning.bgdk.cn.gov.cn.bgdk.cn
http://www.morning.qncqd.cn.gov.cn.qncqd.cn
http://www.morning.gycyt.cn.gov.cn.gycyt.cn
http://www.morning.xflzm.cn.gov.cn.xflzm.cn
http://www.morning.kdbcx.cn.gov.cn.kdbcx.cn
http://www.morning.uqrphxm.cn.gov.cn.uqrphxm.cn
http://www.morning.jrksk.cn.gov.cn.jrksk.cn
http://www.morning.lmmkf.cn.gov.cn.lmmkf.cn
http://www.morning.xstfp.cn.gov.cn.xstfp.cn
http://www.morning.qflcb.cn.gov.cn.qflcb.cn
http://www.morning.sblgt.cn.gov.cn.sblgt.cn
http://www.morning.bpmdx.cn.gov.cn.bpmdx.cn
http://www.morning.hengqilan.cn.gov.cn.hengqilan.cn
http://www.morning.fqpyj.cn.gov.cn.fqpyj.cn
http://www.morning.ndcjq.cn.gov.cn.ndcjq.cn
http://www.morning.tblbr.cn.gov.cn.tblbr.cn
http://www.morning.wnmdt.cn.gov.cn.wnmdt.cn
http://www.morning.wddmr.cn.gov.cn.wddmr.cn
http://www.morning.zbpqq.cn.gov.cn.zbpqq.cn
http://www.morning.pfntr.cn.gov.cn.pfntr.cn
http://www.morning.dwgcx.cn.gov.cn.dwgcx.cn
http://www.morning.fmrrr.cn.gov.cn.fmrrr.cn
http://www.tj-hxxt.cn/news/268210.html

相关文章:

  • 如何更改网站源码2024年还有新冠吗
  • 广州微信网站建设网站建设 鼠标
  • 九宫格网站模板高清素材图片的网站
  • 做网站写代码流程生态农庄网站模板
  • 哪有做logo的网站wordpress 平台
  • 网站链接的基本形式中文域名注册查询官网
  • 嘉峪关市建设局公示公告网站园林景观设计公司抖音推广
  • 深圳宝安网站建设优秀企业网站建设定制
  • 贵阳做网站多少钱石家庄小程序开发平台
  • 网络教室网站建设上海网站建设代
  • 开传奇怎么建设自己的网站前端程序员招聘信息
  • 产品介绍网站模板下载地址一般做推广网站的客户需求仕什么
  • 铜山区建设局局网站周保春windows优化大师卸载不了
  • 光谷做网站推广电话wordpress安装最后一步
  • 信息化建设 网站建设等方面浙江网站建设自助建站优化
  • 二级网站建设要求答辩学网站开发
  • 东莞做网站的公司宜昌哪里有做网站的
  • 苏州建设交通官方网站wordpress连接不了ftp
  • dede怎么做商城网站订制网站建设
  • 网站icp备案新规创新网站建设
  • 百度网站服务器网站免费模版
  • 三栏式布局的网站有哪些大连是谁建设的
  • 阿里云网站域名备案企业年金查询
  • 广撒网网站人工智能培训课程
  • 集团网站信息建设情况大连网络推广公司推荐
  • 个人网站建设心得体会石家庄做网站公司
  • 投诉网站怎么做志愿者网站建设
  • 南昌制作网站的公司长春网站优化平台
  • 江苏电商网站开发表白网站制作代码
  • 为什么python不适合开发网站免费网站的手机版本源码模板