• 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之深入的更多相关文章

  1. JBoss QuickStart之Helloworld

    下载Jboss, quickstart, 按照quickstart说明, mvn clean install. 由于ssl handshake问题(应该是网络连接不稳定), 写了一个脚本不停地尝试bu ...

  2. jboss上的soap web service开发示例

    以下示例,由jboss quickstart示例代码得来: 一.创建一个常规的dynamic web项目,建议支持maven ,项目的关键属性参考下图: 二.定义服务接口及参数对象 HelloWorl ...

  3. EJB之Timer

    EJB Timer 要么: Annotation @Schedule 或者方法前声明@Timeout 要么: 在部署描述中定义timeout-method 如果是使用@Schedule, Timer在 ...

  4. JAVA JPA - 示例用法

    JPA(Java Persistence API)是JSR(Java Specification Requests)的一部分,定义了一系列对象持久化的标准,目前实现这一规范的产品有Hibernate. ...

  5. jboss:跟踪所有sql语句及sql参数

    默认情况下,hibernate/JPA 在server.log中记录的SQL语句,参数都是用?代替的,这样不太方便. 网上留传的p6spy在最新的jboss上(EAP 6.0+版本)貌似已经不起作用了 ...

  6. JBoss 系列九十六:JBoss MSC - 简介及一个简单演示样例

    什么是 JBoss MSC JBoss MSC 即 JBoss Modular Service Container,是第三代 JBoss 产品 JBoss 7和WildFfly的内核,JBoss MS ...

  7. Class loading in JBoss AS 7--官方文档

    Class loading in AS7 is considerably different to previous versions of JBoss AS. Class loading is ba ...

  8. JBoss DataGrid的集群部署与訪问

    集群部署 JDG的缓存模式包含本地(Local)模式和集群(Clustered)模式.本项目採用多节点的Clustered模式部署.数据在多个节点的子集间进行复制.而不是同步拷贝到全部的节点. 使用子 ...

  9. Jboss ESB简介及开发实例

    一.Jboss ESB的简介 1. 什么是ESB.         ESB的全称是Enterprise Service Bus,即企业服务总线.ESB是过去消息中间件的发展,ESB采用了“总线”这样一 ...

随机推荐

  1. HTML5 声明兼容IE的写法(转载)

    HTML5 声明兼容IE的写法(转载)   1 2 3 4 5 6 7 8 9 10 <!DOCTYPE html> <!--[if IE]> <meta http-eq ...

  2. VS更改编辑窗背景

    打开Visual Studio  工具→扩展和更新→联机  在搜索框里输入“background”后,搜索结果有很多插件可以更改 Visual Studio 的背景,选择其中的一项,可以在右边进行预览 ...

  3. Windows无法安装到GPT分区的磁盘的解决方法

    thinkpad 预装win8的机子,硬盘采用gpt分区,在重新安装其它系统的时候是无法安装的,会提示“windows无法安装到这个磁盘,选中的磁盘采用GPT分区 形式".所以先采用下面的方 ...

  4. Linux常用命令学习7---(磁盘管理df du、磁盘的分区和格式化fdisk parted)

    1.磁盘管理    在服务器的维护中,我们需要关心服务器的磁盘使用了多少.还有多少的剩余空间.某个文件有多大.某个文件夹内的所有文件在一起一共占用的多少空间……问题.以便我们在合适的时机为服务器添加硬 ...

  5. xml Schema 基础

    Schema比DTD好在哪儿? 后者简单易用,前者功能更强大也更复杂.DTD可以定义XML文档的结构,但无法对XML元素的内容进行约束,例如,如果希望某个XML元素的内容只能是日期型的数据,DTD就无 ...

  6. 关于opengl库

    The 64-bit OpenGL import library is included in the Windows SDK and gets installed to %ProgramFiles% ...

  7. HDU 2509 Be the Winner nim博弈变形

    Be the Winner Problem Description   Let's consider m apples divided into n groups. Each group contai ...

  8. CustomEvent自定义事件

    javascript与HTML之间的交互是通过事件来实现的.事件,就是文档或浏览器窗口发生的一些特定的交互瞬间.通常大家都会认为事件是在用户与浏览器进行交互的时候触发的,其实通过javascript我 ...

  9. System.Windows.Application.Current.Dispatcher.BeginInvoke

    System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>                        ...

  10. [NOIP2016]换教室 D1 T3 Floyed+期望DP

    [NOIP2016]换教室 D1 T3 Description 对于刚上大学的牛牛来说, 他面临的第一个问题是如何根据实际情况中情合适的课程. 在可以选择的课程中,有2n节课程安排在n个时间段上.在第 ...