• 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. MST 001

    一.String,StringBuffer, StringBuilder 的区别是什么?String为什么是不可变的? 答:   1.String是字符串常量,StringBuffer和StringB ...

  2. 程序中使用ajax时,type为put,或者delete时在 IIS上没效果,发生HTTP Error 405.0 - Method Not Allowed

    其实使用put delete  是在创建webapi中基本才会使用. WebDAV 是超文本传输协议 (HTTP) 的一组扩展,为 Internet 上计算机之间的编辑和文件管理提供了标准.利用这个协 ...

  3. 腾讯QQ形象18年变迁史,最早的QQ企鹅形象居然长这样!

    1999年,腾讯创建之初,这是当时QQ的形象,现在看起来很滑稽,又高又瘦.当时公司并没有专职的设计师,所以这个形象就凑合着用了. 后来,腾讯也觉着上一个形象做的不是特别好,于是在2000年的时候,公司 ...

  4. JS函数节流

    背景:在前端开发中,有时会为页面绑定resize事件,或为一个页面元素拖拽事件(其核心就是绑定mousemove)在一个正常操作中也有可能在一个短时间内触发非常多次事件绑定程序,而DOM操作是很消耗性 ...

  5. Hotaru's problem(hdu 5371)

    题意:给出一个数字串,询问最长的子串,满足以下要求:将子串平均分为三部分,一三部分相等,一二部分对衬. /* 在manachar的基础上,枚举回文串的中心,再找第三部分. */ #include< ...

  6. iOS文件类型判断

    最近在做的东西有下载zip,只是服务器发送过来的是二进制,需要根据二进制来判断是什么类型的文件,从而进行保存操作.起初很不理解,到后来发现可以通过二进制的前2位的ascii码来进行判断.如下: // ...

  7. Spring事务管理

    Spring是SSH中的管理员,负责管理其它框架,协调各个部分的工作.今天一起学习一下Spring的事务管理.Spring的事务管理分为声明式跟编程式.声明式就是在Spring的配置文件中进行相关配置 ...

  8. tangram2.6(XE2)\Demo\notify\notifyGroup.groupproj

    1.以下此异常,为exe没有加载到Tangram_Core.bpl 放到exe当前文件夹下即可 2.此例子的接口实现在exe中,exe中下发通知到dll,dll 中 as 获取接口传窗体到exe中: ...

  9. CSS Table Gallery

    http://icant.co.uk/csstablegallery/tables/99.php

  10. 基于Proteus仿真的Arduino学习(1)——Arduino Uno最小系统及LED的简单使用

    一.前言:  A.Arduino简介 Arduino是由一个欧洲开发团队于2005年冬季开发.其成员包括Massimo Banzi.David Cuartielles.Tom Igoe.Gianluc ...