0

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

Hubi
  • 440
  • 1
  • 11
  • 25

1 Answers1

2

In my opinion there are 2 ways to do it:

  1. User AspectJ. Like these two exemples: 1, 2

  2. Create you own Annotation. Then you can receive the methods you want to trigger as the parameters. Something like this:

     @MyCustomTriggerAnnotation(methodsToBeTriggered= {methodA, methodB})
     public void test(){
    
     }
    
Eduardo Briguenti Vieira
  • 4,351
  • 3
  • 37
  • 49