英文:
Is there a way to monitor methods so that another method is executed elsewhere in the code?
问题
有人可以帮助我并解释如何最好地观察一个方法。这意味着当执行某个特定方法时,整个系统应该在另一个点内部重新计算,例如。例如,当上传文件时,后台应该触发某些计算。
观察者(Observer)已被弃用,属性更改监听器(PropertyChangeListener)在我的情况下不起作用。
有人有想法或模式如何在Java中映射这种情况吗?
谢谢
英文:
Can someone help me and explain how best to observe a method. This means that when a certain method is executed, the entire system should be recalculated internally at another point, for example. The same for example when a file is uploaded, then certain calculations should be triggered in the background.
Observer is deprecated and PropertyChangeListener does not help me in my case i think.
Does anyone have an idea or pattern how to map this case in Java?
Thanks
答案1
得分: 2
在我看来,有两种方法可以实现:
1)使用用户AspectJ。就像这两个例子:1,2。
2)创建您自己的注解。然后,您可以接收要作为参数触发的方法。类似于这样的形式:
@MyCustomTriggerAnnotation(methodsToBeTriggered= {methodA, methodB})
public void test(){
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论