English 中文(简体)
AOP with Local Variable Annotation
原标题:AOP with Local Variable Annotations

我想利用当地可变的说明来更好地执行《公约》。 一种想法是采用“未来”和“T>”概念,采用“说明”作为代理。

@NonBlocking ExpensiveObject exp = new ExpensiveObject(); 
//returns immediately, but has threaded out instantiation of the ExpensiveObject.

exp.doStuff(); 
//okay, now it blocks until it s finished instantiating and then executes #doStuff

我能否用这种 some子 sick住AspectJ,并了解我希望用当地可变的说明做些什么? 我知道其他透镜已经表明, Java确实支持.,但会是魔鬼。 我确实不想绕过未来和打破cap头。

最佳回答

你不能用代理人这样做,但如果你注意到这种类型,而不是地方变量,那么通过人工编码进行编织会让你去。 (我不认为当地可变准入是一个要点。) 不管怎么说,这里有一些法典。

说明:

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Later {}

具有这一说明的一类:

package com.dummy.aspectj;
@Later
public class HeavyObject{

    public HeavyObject(){
        System.out.println("Boy, I am heavy");
    }
}

主要类别:

package com.dummy.aspectj;
public class HeavyLifter{

    public static void main(final String[] args){
        final HeavyObject fatman = new HeavyObject();
        System.out.println("Finished with main");
    }

}

以及一个方面:

package com.dummy.aspectj;
public aspect LaterAspect{

    pointcut laterInstantiation() :
        execution(@Later *.new(..))    ;

    void around() : laterInstantiation() {
        new Thread(new Runnable(){
            @Override
            public void run(){
                System.out.println("Wait... this is too heavy");

                try{
                    Thread.sleep(2000);
                } catch(final InterruptedException e){
                    throw new IllegalStateException(e);
                }
                System.out.println("OK, now I am up to the task");
                proceed();
            }
        }).start();
    }

}

这里指的是作为AspectJ/Java申请方从ec子中转来的重型设备的产出:

Finished with main
Wait... this is too heavy
OK, now I am up to the task
Boy, I am heavy
问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签