• 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. python des ecb 加密 demo

    # -*- coding:utf-8 -*- from pyDes import * def hexString2bytes(src): ret =[] for i in range(len(src) ...

  2. C#中的日期处理函数

    C#中的日期处理函数 //2013年4月24日 this.TextBox6.Text = System.DateTime.Now.ToString("D"); //2013-4-2 ...

  3. InnoDB全文索引:N-gram Parser【转】

    本文来自:http://mysqlserverteam.com/innodb%E5%85%A8%E6%96%87%E7%B4%A2%E5%BC%95%EF%BC%9An-gram-parser/ In ...

  4. SQL Server服务器上需要导入Excel数据的必要条件

    SQL Server服务器上需要导入Excel数据,必须安装2007 Office system 驱动程序:数据连接组件,或者Access2010的数据库引擎可再发行程序包,这样就不必在服务器上装Ex ...

  5. Python之路,Day2 - Python基础2

    def decode(self, encoding=None, errors=None): """ 解码 """ ""& ...

  6. HTTP状态码(2xx,3xx,4xx,5xx)

    HTTP状态码负责表示客户端请求的返回结果,标记服务器的处理结果. HTTP常用状态码分为5种:   类别 原因短语 1xx Informational(信息状态码) 接受请求正在处理 2xx Suc ...

  7. Ruby基本类型

    #!/usr/bin/ruby =begin Ruby支持的有5种类型的变量 全局变量:以$开头 未初始化的全局变量的值为0 并使用-w选项产生警告 全局变量的赋值会改变全局状态 不推荐使用全局变量  ...

  8. caffe初试(一)happynear的caffe-windows版本的配置及遇到的问题

    之前已经配置过一次caffe环境了: Caffe初试(一)win7_64bit+VS2013+Opencv2.4.10+CUDA6.5配置Caffe环境 但其中也提到,编译时,用到了cuda6.5,但 ...

  9. Word中一些问题解决

    word图片不显示或显示不全怎么办? http://jingyan.baidu.com/article/0f5fb099c5cb7a6d8334ea06.html

  10. iOS ARC 下的单例模式

    #import <Foundation/Foundation.h> @interface RYSingleExample : NSObject<NSCopying> +(ins ...