- 浏览: 70971 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
george.gu:
lqjacklee 写道怎么解决。。 First: Conf ...
Bad version number in .class file -
lqjacklee:
怎么解决。。
Bad version number in .class file -
flyqantas:
would you pleade left more mate ...
UML Extension
I had heared about AOP almost 7 years but only used it in two projects. 7 Years, I still only know few about AOP, if i were not involved in that two projects, i would still know that few.
The fact is always like that:
- Hear about it.
- Know how to use it.
- Use it in project
- Know what's problem it solved and try to enhance it.
First story: Why there is no "before" or "after" method execution Advice?
Normally for a AOP, we can say there are point-cuts or events:
- Befroe execution
- Before return
- Exception catch and processing in case exception raised
First time, I use AOP with EJB3. Thanks to annotation @Interceptor and @AroudInvoke, i can define AOP interceptors easily. But for a long time during, I was always wondering:
- Why there is only "around " invokea method, but no "before" or "after" invoke methods?
Second story: Exception used as logical condition had been intercepted by prior interceptor
- Catch Exception from point-cut and retry execution in case there is exception.
- If max retry number catched, marks Transaction to be "Rollback Only".
<tx:advice id="tx-advice" transaction-manager="myTransactionManager"> <tx:attributes> <tx:method name="*" propagation="REQUIRED" rollback-for="java.lang.Exception"/> </tx:attributes> </tx:advice>
<bean id="myTransactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory"> <ref bean="mySessionFactory"/> </property> </bean>
<bean id="TransactionRetryInterceptor" class="com.MyTransactionRetryInterceptor"/> |
Here is the shanpshot for MyTransactionRetryInterceptor:
public Object invoke(MethodInvocation invocation) throws Throwable { int retryCount = 0; logger.info("TRANSACTION BEGIN"); while (true) { try { ReflectiveMethodInvocation inv = (ReflectiveMethodInvocation) invocation; MethodInvocation anotherInvocation = inv.invocableClone(); Object obj = anotherInvocation.proceed(); logger.info("TRANSACTION END: OK"); return obj; } catch (Exception ex) { // If reached maximum number of retries then just rethrow this exception immediately. if (++retryCount > maxRetryCount) { logger.error ("TRANSACTION FAIL: max retries reached:", ex); throw ex; }
//TODO...check if the transaction need to be retried, if yes, retry it. Otherwise, // throw the exception directly. }
// Clean-up & delay for a while before retrying. cleanupBeforeRetrying(); delay(); } } |
- call A.dosomething() to execute some logical.
- If A.dosomething() raise exception C, that means some special case happen, B should process dedicated use case.
- Class B invoke Class A to do something.
- Intercaptor will catch the exception C raised by A and mark Transaction "rollback only" once reach max retry number.
- Intercaptor delegate exception C to class B,
- Class B executed completely and try to submit the Transaction.
- Transaction rollback as it is marked "Rollback Only".
- Do not set point-cut on class A.
- Or do not use exception as business logical condition.
- Or use some other adapter who provide same behavior but has no that transaction interceptor. It is like first workaround.
- There are some Interceptors/Advisors which are not defined by myself.
发表评论
-
javax.naming.CommunicationException: remote side declared peer gone on this JVM.
2012-07-11 09:44 2329javax.naming.ServiceUnavailable ... -
Generate special format numbers
2012-04-27 00:06 867DecimalFormat df = new DecimalF ... -
Singleton Service in Weblogic Cluster
2012-03-21 00:12 653http://blog.csdn.net/mobicents/ ... -
Scheduled ThreadPool Executor suppressed or stopped after error happen
2012-03-20 16:54 1004ScheduledThreadPoolExecutor ... -
Bad version number in .class file
2012-01-27 00:35 844Bad version number in .class fi ... -
User Data Header in SMPP SUBMIT_SM
2012-01-25 22:30 2298SMPP optional Parameters for ... -
jQuery study
2011-12-28 00:44 0to be study -
Java is Pass-by-Value or Pass-by-Reference?
2011-12-19 19:18 653What's saved in Object Referenc ... -
java.util.Properties: a subclass of java.util.Hashtable
2011-12-13 06:57 735I met a problem this afternoon ... -
Jmock usage
2011-12-02 05:37 0Discuss how Jmock working. -
Oracle Index Usage
2011-12-15 05:26 570Like a hash mapping for record' ... -
AOP(2):AOP与动态代理JDK Proxy and Cglib Proxy
2011-05-12 16:20 967使用动态代理(JDK Proxy 或者Cglib Proxy) ... -
异步系统设计:push vs pull
2011-05-02 23:59 1109今天讨论问题时,有个同事说系统A是主动去系统B里“拿”消息,我 ... -
Velocity Usage
2011-04-28 22:52 962You can find velocity mannua ... -
Java Regular Expression (Java正则表达式)
2011-04-23 06:58 892In current Project, we need to ... -
XML Parser:DOM + XPath
2011-04-23 06:30 1158There are many kinds of XML Par ... -
File upload and download in Java Web Application.
2011-04-21 21:08 1671最近在项目中遇到一个下载文件的老问题。之所以说是老问题,因为在 ... -
Manage zip content using Java APIs
2011-04-21 18:14 985JDK provide a set of utils to c ... -
Beanshell: how and where to use beanshell
2011-04-21 00:33 2049How to use beanshell beansh ... -
OXM: JAXB2.0 in JDK1.6
2011-04-20 22:53 12031.1.1 JAXB 2.0: ObjectàXML ...
相关推荐
AOP联盟:aopalliance.jar API包a set of AOP Java interface .
开发工具 aopalliance-1.0开发工具 aopalliance-1.0开发工具 aopalliance-1.0开发工具 aopalliance-1.0开发工具 aopalliance-1.0开发工具 aopalliance-1.0开发工具 aopalliance-1.0开发工具 aopalliance-1.0开发工具...
spring aop应用 spring aop应用 spring aop应用 spring aop应用 spring aop应用
aopalliance-1.0.rar完整版资源
Spring AOP(面向切面编程)作为Spring框架的一个重要部分,为Java开发者提供了一个强大而灵活的工具来切入代码执行流程,实现关注点的分离。通过详细解析Spring AOP的源码,本文揭示了其背后的核心原理和实现机制。...
关于AOP注解前置通知、后置通知、返回通知、异常通知的注解注释及应用
aopalliance源码
赠送jar包:spring-aop-5.0.10.RELEASE.jar; 赠送原API文档:spring-aop-5.0.10.RELEASE-javadoc.jar; 赠送源代码:spring-aop-5.0.10.RELEASE-sources.jar; 赠送Maven依赖信息文件:spring-aop-5.0.10.RELEASE....
Spring AOP 入门 作者:廖雪峰
《开发者突击:精通AOP整合应用开发(AspectWerkz+Aspectl+Spring)》以AOP基础理论为主线,首先讲解AOP的产生与发展、为什么要应用AOP、AOP的核心概念,然后再详细讲解AspectWerkz、AspectJ、Spdng框架的AOP应用开发...
AOP在j2ee构架中的应用
NULL 博文链接:https://chenhongwei0924.iteye.com/blog/845772
使用Spring开发的AOP小程序,供学习使用
本书以AOP基础理论为主线,首先讲解AOP的产生与发展、为什么要应用AOP、AOP的核心概念,然后详细讲解AspectWerkz、AspectJ、Spring框架的AOP应用开发技术。 随书附赠的光盘内容为本书开发的案例程序包。本书内容循序...
AOP 的利器:ASM 3_0 介绍,很好的书
spring aop spring aop spring aop spring aop spring aop spring aop spring aop spring aop spring aop
本文首先介绍了AOP 的基本思想,然后针对它在JAVA 语言 中的实现,具体介绍了JAVA 的动态代理来怎样实现一个简单的AOP 容器
AOP实现机制和应用的研究,需要的可以看看
AOP思想和事务注解应用