- 浏览: 96402 次
文章分类
最新评论
-
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 530### how to access k8s web conso ... -
Call Stored Procedure with JPA 2.1
2018-06-27 10:57 619JPA 2.1 introduces APIs to call ... -
java 8 time api test
2017-08-29 05:40 440public class ParseUtcDateTime ... -
Setup ApiKey in header with Swagger generated client code
2017-08-23 06:41 439@Value("${api.base.path} ... -
Simple tool to monitor jvm memory usage and garbage collection
2016-10-13 06:06 320JDK has built-in tool to moni ... -
Externalize Application Config properties with JBoss 7.1
2017-06-02 12:09 307If you have configuration pro ... -
JPA native query does not support setting list parameters
2014-03-27 06:45 972you might want to do the ... -
Owning Side and Inverse Side of JPA entity relationships
2013-09-10 07:08 760Entity relationships may be b ... -
avoid setParameter for "order by" in JPQL
2013-03-07 05:55 752you might want to create a JP ... -
JPA Path Expression, operator IN and Collection properties
2013-01-23 16:25 1340If we want to select the Orde ... -
与JEE6/EJB3.1相比, Spring framework 丧失了几乎所有的优势
2013-01-19 13:13 997The Spring framework was a ma ... -
Simple EasyMock tutorial
2012-12-20 11:57 622http://veerasundar.com/blog/20 ... -
Servlet 3.0 @WebFilter and @WebServlet
2012-12-04 07:09 2634Servlet 3.0 provides new annota ... -
Why JSF2 @ViewScoped not working?
2012-12-03 06:55 1343javax.faces.bean.ViewScoped sai ... -
When to configure an XA datasource?
2012-11-16 12:58 1226If you ever came across this wa ... -
java ee transaction and datasource concepts
2012-11-10 13:48 9891. What is a transaction? A tra ... -
pass params to primefaces confirmation dialog box
2012-09-28 19:30 1301<p:dataTable id="idStuD ... -
Handle Big Dataset with Real Pagination with Primefaces 3.3 LazyDataModel
2012-09-21 13:41 5584If you have millions of record ... -
why Oracle sequence not working with JPA entity ID?
2012-09-19 08:08 936Suppose you have an Oracle seq ...
相关推荐
mongodb-async-driver-2.0.1 jar包
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): ...
我们还是回到一个ChildProcess的实例,只需用.then()和.catch()添加到它,使其答应友好。 安装 npm install --save child-process-async 用法 // OLD: const { exec , spawn } = require ( 'child_process' ) ; // ...
前端开源库-babel-helper-remap-koa2-async-to-generatorbabel-helper-remap-koa2-async-to-generator,将异步函数转换为ES2015生成器(koav2->koav1)。
前端开源库-babel-plugin-transform-async-to-promisesBabel插件将异步转换为承诺,将异步/等待转换为承诺链
akka-persistence-sql-async, 一个用于akka持久性的日志和快照存储 akka-persistence-sql-async 的日志和快照存储插件( akka持久化插件。 Akka-persistence-sql-async执行由 scalikejdbc异步查询,它提供非阻塞api来...
vue-async-computed, Vue.js的异步计算属性 vue-async-computed 这里插件的为Vue兼容 ! 可以使用这个插件在Vue中计算出异步计算的属性。不使用这里插件,你无法执行这里操作:new Vue({ data: { us
android-async-http官方项目:来自Github; 该项目中包含了多个版本的android-async-http.jar包,目前最新版本是:android-async-http-1.4.5.jar; 地址:原项目地址:https://github.com/loopj/android-async-http
android-async-http 1.4.9版本,附带了其依赖的httpclient包
最新异步网络请求android-async-http-1.4.5.jar
android的异步网络加载,方便使用,免去多余的代码
android-async-http开源框架可以是我们轻松的获取网络数据或者向服务器发送数据,使用起来也很简单,具体详细使用看官网:https://github.com/loopj/android-async-http
android-async-http-1.4.9.jar是一般使用Apache HTTP Client或者采用HttpURLConnect,但是直接使用这两个类库需要写大量的代码才能完成网络post和get请求,而使用android-async-http这个库可以大大的简化操作,它是...
android-async-http是Android上的一个异步、基于回调的HTTP客户端开发包,建立在Apache的HttpClient库上.zip,太多无法一一验证是否可用,程序如果跑不起来需要自调,部分代码功能进行参考学习。
强大的网络请求库,主要特征如下: 处理异步Http请求,并通过匿名内部类处理回调结果 Http请求均位于非UI线程,...通过线程池处理并发请求 处理文件上传、下载 响应结果自动打包JSON格式 自动处理连接断开时请求重连
前端开源库-multihashing-async多哈希异步,多哈希函数
1)包里包含android-async-http-1.4.11.jar 和 httpclient-4.5.8.jar两个文件 2)强大的网络请求库,主要特征如下: 处理异步Http请求,并通过匿名内部类处理回调结果 Http请求均位于非UI线程,不会阻塞UI操作 通过...
android.async.http.jar包 包含1.2.0 至 1.4.8 版本。
比较好用的安卓异步下载包,android-async-http-1.4.6.jar
YCSB需要这个已经废弃的旧库,可...mvn install:install-file "-Dfile=mongodb-async-driver-2.0.1.jar" "-DgroupId=com.allanbank" "-DartifactId=mongodb-async-driver" "-Dversion=2.0.1" "-Dpackaging=jar" ```