2

I have used the simple annotations given to us in the JDK and by other libraries such as hibernate, but I've never written my own. Can someone help me decide if an annotation is the proper way to do this?

I want to annotate a method like this:

@MyAnnotation(5)
public void foo() {
     methodThatMightTakeLongerThan5();
}

When foo takes longer than 5 seconds, print a message to my log file. Is this possible with Annotations? Is that the preferred implementation?

Going a bit further...I'd like to be able to modify the value passed to the annotation via JMX bean so that I can modify it at runtime if I want to. Is that possible/preferred?

4

1 回答 1

0

您可以放入methodThatMightTakeLongerThan5();Thread 中,在 中运行线程foo(),使用 等待 5 秒Thread.sleep(5000);,然后检查线程是否已完成。如果没有,请打印您需要的任何内容。我假设有一种方法可以检查线程是否正在运行,但我不确定。

于 2013-04-08T23:48:09.030 回答