JBoss QuickStart之深入
- EJB-Asynchronous
EJB中提供异步调用的方法."A session bean can expose methods with asynchronous client invocation semantics. For asynchronous invocations, control returns to the client before the container dispatches the invocation to a bean instance. An asynchronous method is a business method exposed through one or more of the Remote business, Local business, or no-interface session bean views.
Asynchronous methods can return a Future<V> object that allows the client to retrieve a result value, check for exceptions, or attempt to cancel an in-progress invocation." -From JSR 318: Enterprise JavaBeansTM,Version 3.1EJB Core Contracts and RequirementsNovember 5, 2009Version 3.1, Final Release
最简单就是使用注解, @Asynchronous, 方法可以返回一个Future<V>对象,当然也可以不返回任何,即void. 譬如如下代码:
@Asynchronous
@Override
public Future<String> longerRunning(long sleepTime) {
LOGGER.info("Will wait for " + sleepTime + "ms");
try {
Thread.sleep(sleepTime);
} catch (InterruptedException e) {
}
LOGGER.info("returning the result");
return new AsyncResult<String>("returning at " + new Date() + ", duration was " + sleepTime + "ms");
}
如果异步调用抛出异常咋办?如下例子failure()方法(类似上面的longerRunning方法)为一个声明为异步的方法, 但会抛出异常, 异常会在调用x.get()时候抛出ExecutionException, 然后get出来就可以得到原始的异常.
这个是J2SE的东西, 猜测容器应该使用ExecutorService去调用这些方法,然后封装,返回Future对象.
与Timer不同,timer采用的是J2SE的util包中的TimerTask去实现的(JBoss),而这个异步调用采用cocurrent包中的ExecutorService以及Future实现.
private void callAsyncWithFailure() throws InterruptedException {
Future<String> x = accessBean.failure(); // this method will return successfully, because the invocation will be successful!
try {
x.get(); // this will not return successfully
} catch (ExecutionException e) {
// the IllegalAccessException is thrown by the bean method
if (e.getCause() instanceof IllegalAccessException) {
// This is the expected behavior
LOGGER.info("Catch the expected Exception of the asynchronous execution!");
} else {
throw new RuntimeException("Unexpected ExecutionException during asynchronous call!", e);
}
}
}
- tasks
这个涉及JPA(Java Persistence API), JPA的前世今生需要搞搞明白,否则不明白与Hibernate之间的关系。
JPA的背景及现在:
About JPA and Hibernate found in JBoss_Enterprise_Application_Platform-6-Development_Guide-en-US.pdf:
The Java Persistence API (JPA) is the standard for using persistence in Java projects. Java EE 6
applications use the Java Persistence 2.0 specification, documented here:
http://www.jcp.org/en/jsr/detail?id=317.
Hibernate EntityManager implements the programming interfaces and life-cycle rules defined by the
specification.
--From offical JBoss Developer Guide
TBC ...
JBoss QuickStart之深入的更多相关文章
- JBoss QuickStart之Helloworld
下载Jboss, quickstart, 按照quickstart说明, mvn clean install. 由于ssl handshake问题(应该是网络连接不稳定), 写了一个脚本不停地尝试bu ...
- jboss上的soap web service开发示例
以下示例,由jboss quickstart示例代码得来: 一.创建一个常规的dynamic web项目,建议支持maven ,项目的关键属性参考下图: 二.定义服务接口及参数对象 HelloWorl ...
- EJB之Timer
EJB Timer 要么: Annotation @Schedule 或者方法前声明@Timeout 要么: 在部署描述中定义timeout-method 如果是使用@Schedule, Timer在 ...
- JAVA JPA - 示例用法
JPA(Java Persistence API)是JSR(Java Specification Requests)的一部分,定义了一系列对象持久化的标准,目前实现这一规范的产品有Hibernate. ...
- jboss:跟踪所有sql语句及sql参数
默认情况下,hibernate/JPA 在server.log中记录的SQL语句,参数都是用?代替的,这样不太方便. 网上留传的p6spy在最新的jboss上(EAP 6.0+版本)貌似已经不起作用了 ...
- JBoss 系列九十六:JBoss MSC - 简介及一个简单演示样例
什么是 JBoss MSC JBoss MSC 即 JBoss Modular Service Container,是第三代 JBoss 产品 JBoss 7和WildFfly的内核,JBoss MS ...
- Class loading in JBoss AS 7--官方文档
Class loading in AS7 is considerably different to previous versions of JBoss AS. Class loading is ba ...
- JBoss DataGrid的集群部署与訪问
集群部署 JDG的缓存模式包含本地(Local)模式和集群(Clustered)模式.本项目採用多节点的Clustered模式部署.数据在多个节点的子集间进行复制.而不是同步拷贝到全部的节点. 使用子 ...
- Jboss ESB简介及开发实例
一.Jboss ESB的简介 1. 什么是ESB. ESB的全称是Enterprise Service Bus,即企业服务总线.ESB是过去消息中间件的发展,ESB采用了“总线”这样一 ...
随机推荐
- iOS9 新功能:Support Universal Links
先看官方文档:https://developer.apple.com/library/ios/documentation/General/Conceptual/AppSearch/UniversalL ...
- 多线程下NSOperation、NSBlockOperation、NSInvocationOperation、NSOperationQueue的使用
本篇文章主要介绍下多线程下NSOperation.NSBlockOperation.NSInvocationOperation.NSOperationQueue的使用,列举几个简单的例子. 默认情况下 ...
- nodeJS搭建本地服务器
准备工作: 安装Node JS: 1:安装全局express:在express4.x版本中,安装时语句变为了这样: npm install -g express-generator 2:创建项目: 选 ...
- mysql远程连接问题
问题:在服务器里面新安装一个MYSQL数据库,结果在远程电脑连接不上,并提示“服务器连接错误Host 'XXX' is not allowed to connect to this MySQL ser ...
- [LeetCode] Reverse Linked List II
Reverse a linked list from position m to n. Do it in-place and in one-pass. For example:Given 1-> ...
- [MongoDB]MongoDB的优缺点及与关系型数据库的比较
汇总: 1. [MongoDB]安装MongoDB2. [MongoDB]Mongo基本使用:3. [MongoDB]MongoDB的优缺点及与关系型数据库的比较4. [MongoDB]MongoDB ...
- 关闭英文拼写检查,关闭xml验证
http://blog.sina.com.cn/s/blog_70b623e4010173ce.html eclipse里面的许多设置对于国内开发者日常使用不太适用,反而会成为干扰.既然是完全可配置的 ...
- css3 tween
/* * Tween.js * t: current time(当前时间) * b: beginning value(初始值) * c: change in value(变化量) * d: durat ...
- 关于datatime 时间处理模块:
import time from datetime import datetime from datetime import timedelta aHour= ...
- BestCoder Round #85(ZOJ1569尚未验证)
A题 子序列和啊,就要想到前缀和的差.这个转换一定要!记着!那么i到j的一段子序列和Sij%m == 0就等价于(Sj-Si-1)%m == 0 了,那么什么意思呢?就是如果有两段前缀和%m的模是一 ...