- 浏览: 100058 次
文章分类
最新评论
-
jXee:
lgs0626 写道求源码,兄弟给共享下吧 "jee ...
jee6 学习笔记 4 - CRUD 2: View Details, Primefaces row selection -
lgs0626:
求源码,兄弟给共享下吧
jee6 学习笔记 4 - CRUD 2: View Details, Primefaces row selection
If your request processing takes long time to run, client might be timed out before processing completed. One solution is to send back the response (method returns) and then process the request in a different thread.
/* * This is the normal sync processing. Client might be timed out if * processing takes a while to finish and then the method returns. */ @POST @Path("/test") public void test() { System.out.println("==== Normal test started"); try { System.out.println("==== Normal task started: " + Instant.now()); Thread.sleep(15000); System.out.println("==== Normal task finished: " + Instant.now()); } catch (InterruptedException ie) {} System.out.println("==== Normal test completed"); } ## console output: everything happens in order. If it took longer than 15 seconds, client could be timed out: ==== Normal test started ==== Normal task started: 2017-10-12T01:25:10.054Z ==== Normal task finished: 2017-10-12T01:25:25.055Z ==== Normal test completed
/* Async processing. The method would return immediately after the request received. * processing(task) would happen afterwards, so that client would not be timed out. */ @POST @Path("/testAsync") public Response testAsync() { System.out.println(">>>> Async test started"); Runnable task = () -> { try { System.out.println(">>>> async task started: " + Instant.now()); //Thread.sleep(15000); TimeUnit.SECONDS.sleep(15); System.out.println(">>>> async task finished: " + Instant.now()); } catch (InterruptedException ie) {} }; Executors.newSingleThreadExecutor().execute(task); System.out.println(">>>> Async test completed"); return Response.status(OK).entity("service completed!").build(); } ## console output: method returns immediately and then task starts in a different thread: >>>> Async test started >>>> Async test completed >>>> async task started: 2017-10-12T01:25:33.673Z >>>> async task finished: 2017-10-12T01:25:48.675Z
/** * The following is jax-rs 2.0 AsyncResponse. */ @POST @Path("/asyncResponse") public void testAsyncResponse(@Suspended AsyncResponse asyncResponse) { System.out.println("## testAsyncResponse started"); new Thread() { public void run() { try { System.out.println("## testAsyncResponse task started: " + Instant.now()); Thread.sleep(15000); System.out.println("## testAsyncResponse task finished: " + Instant.now()); } catch (InterruptedException ie) {} // Send processing result: if suspended AsyncResponse is not resumed or cancelled, client would be timed out Response response = Response.ok().entity("Processed Successfully").build(); asyncResponse.resume(response); } }.start(); System.out.println("## testAsyncResponse completed"); }
发表评论
-
ActiveMQ and Spring JMS Framework Message Loss
2019-06-28 07:15 29Java Message Service (JMS) prov ... -
how to proxy to k8s web console
2018-06-28 07:16 568### how to access k8s web conso ... -
Call Stored Procedure with JPA 2.1
2018-06-27 10:57 670JPA 2.1 introduces APIs to call ... -
java 8 time api test
2017-08-29 05:40 480public class ParseUtcDateTime ... -
Setup ApiKey in header with Swagger generated client code
2017-08-23 06:41 479@Value("${api.base.path} ... -
Simple tool to monitor jvm memory usage and garbage collection
2016-10-13 06:06 364JDK has built-in tool to moni ... -
Externalize Application Config properties with JBoss 7.1
2017-06-02 12:09 339If you have configuration pro ... -
JPA native query does not support setting list parameters
2014-03-27 06:45 1013you might want to do the ... -
Owning Side and Inverse Side of JPA entity relationships
2013-09-10 07:08 811Entity relationships may be b ... -
avoid setParameter for "order by" in JPQL
2013-03-07 05:55 780you might want to create a JP ... -
JPA Path Expression, operator IN and Collection properties
2013-01-23 16:25 1399If we want to select the Orde ... -
与JEE6/EJB3.1相比, Spring framework 丧失了几乎所有的优势
2013-01-19 13:13 1038The Spring framework was a ma ... -
Simple EasyMock tutorial
2012-12-20 11:57 678http://veerasundar.com/blog/20 ... -
Servlet 3.0 @WebFilter and @WebServlet
2012-12-04 07:09 2697Servlet 3.0 provides new annota ... -
Why JSF2 @ViewScoped not working?
2012-12-03 06:55 1372javax.faces.bean.ViewScoped sai ... -
When to configure an XA datasource?
2012-11-16 12:58 1266If you ever came across this wa ... -
java ee transaction and datasource concepts
2012-11-10 13:48 10491. What is a transaction? A tra ... -
pass params to primefaces confirmation dialog box
2012-09-28 19:30 1338<p:dataTable id="idStuD ... -
Handle Big Dataset with Real Pagination with Primefaces 3.3 LazyDataModel
2012-09-21 13:41 5626If you have millions of record ... -
why Oracle sequence not working with JPA entity ID?
2012-09-19 08:08 972Suppose you have an Oracle seq ...
相关推荐
在Android应用开发中,网络通信是必不可少的一部分,而`android-async-http`库是一个非常流行的异步HTTP客户端库,特别适合处理与服务器的交互。这个库由Leonardo Uribe创建,它提供了简单易用的API,使开发者可以...
Build Status ...https://github.com/loopj/android-async-http/blob/1.4.9/CHANGELOG.md Javadoc Latest Javadoc for 1.4.9 release are available here (also included in Maven repository): ...
MongoDB异步驱动程序(mongodb-async-driver)是为Java开发者设计的一个库,它允许应用程序以非阻塞的方式与MongoDB服务器进行通信,提高了处理大量并发请求的能力。 在"mongodb-async-driver-2.0.1.jar"这个特定...
Android-Async-Http是一个流行的开源库,用于在Android应用程序中执行异步HTTP请求。这个库由Loopj开发,简化了网络交互的过程,使得开发者能够更高效地处理网络操作,而无需阻塞主线程,从而避免ANR(Application ...
前端开源库-babel-helper-remap-koa2-async-to-generatorbabel-helper-remap-koa2-async-to-generator,将异步函数转换为ES2015生成器(koav2->koav1)。
android-async-http-1.4.9.jar是一般使用Apache HTTP Client或者采用HttpURLConnect,但是直接使用这两个类库需要写大量的代码才能完成网络post和get请求,而使用android-async-http这个库可以大大的简化操作,它是...
mongodb-async-driver-2.0.1驱动文件 jar MongoDB Async Java Driver Documentation Welcome to the MongoDB Async Java driver documentation hub. Getting Started The Getting Started guide contains ...
3. **转换过程**:`babel-plugin-transform-async-to-promises`工作原理是,首先识别出`async function`和`await`关键字,然后将它们替换为基于Promise的操作,如`.then()`和`.catch()`。这样,即使目标环境不支持`...
`android-async-http-1.4.9` 是一个专为Android设计的异步HTTP库,它简化了网络请求的处理流程,使开发者能够更高效地进行网络通信。这个库由Leonard Brünings创建,并且在早期的Android开发中广泛使用。 ### 异步...
vue-async-computed, Vue.js的异步计算属性 vue-async-computed 这里插件的为Vue兼容 ! 可以使用这个插件在Vue中计算出异步计算的属性。不使用这里插件,你无法执行这里操作:new Vue({ data: { us
强大的网络请求库,主要特征如下: 处理异步Http请求,并通过匿名内部类处理回调结果 Http请求均位于非UI线程,...通过线程池处理并发请求 处理文件上传、下载 响应结果自动打包JSON格式 自动处理连接断开时请求重连
我们还是回到一个ChildProcess的实例,只需用.then()和.catch()添加到它,使其答应友好。 安装 npm install --save child-process-async 用法 // OLD: const { exec , spawn } = require ( 'child_process' ) ; // ...
"Android-Async-Http"是一个流行的开源框架,专为Android平台设计,用于简化网络请求处理。这个框架的主要目标是让Android开发者能够更高效、更轻松地进行异步HTTP通信,从而获取网络数据或向服务器发送数据。在...
android-async-http官方项目:来自Github; 该项目中包含了多个版本的android-async-http.jar包,目前最新版本是:android-async-http-1.4.5.jar; 地址:原项目地址:https://github.com/loopj/android-async-http
1)包里包含android-async-http-1.4.11.jar 和 httpclient-4.5.8.jar两个文件 2)强大的网络请求库,主要特征如下: 处理异步Http请求,并通过匿名内部类处理回调结果 Http请求均位于非UI线程,不会阻塞UI操作 通过...
`fis-postprocessor-require-async`库则是针对`require.async`进行后处理的工具,它能够分析并记录`require.async`加载的组件,使得构建过程更加智能化和可控。 首先,我们需要理解`require.async`的工作原理。在...
最新异步网络请求android-async-http-1.4.5.jar
android的异步网络加载,方便使用,免去多余的代码
**前端开源库 `multihashing-async` 深度解析** 在当今的Web开发领域,前端开源库扮演着至关重要的角色,它们为开发者提供了强大的工具和功能,以提高开发效率和代码质量。`multihashing-async` 就是这样一个专为...
android-async-http开源框架可以是我们轻松的获取网络数据或者向服务器发送数据,使用起来也很简单,具体详细使用看官网:https://github.com/loopj/android-async-http