[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] Could an advice be declared synchronized, like declaring a synchronized method?
|
Yes you can use a synchronized statement in the body of an advice. See the example below (which compiles & runs successfully). I don't believe you can use the synchronized keyword before advice (it fails for me).
public aspect SynchAdvice {
before() : execution(* main(..)) {
synchronized(this) {
System.out.println("entering advice on thread "+Thread.currentThread());
}
}
public static void main(String args[]) {
// exercise for the reader: spawn several threads that call back on main
// with a delay before completing to prove it works
}
}
Ron
Ron Bodkin
Chief Technology Officer
New Aspects of Software
m: (415) 509-2895
> ------------Original Message------------
> From: "Guofeng Zhang" <guofengzhang@xxxxxxxxxxxxx>
> To: <aspectj-users@xxxxxxxxxxx>
> Date: Wed, Mar-3-2004 10:05 PM
> Subject: [aspectj-users] Could an advice be declared synchronized, like declaring a synchronized method?
>
>
> Could an advice be declared synchronized, or use synchronized statement in the body of an advice?
>
> If not, how to code a thread-safe advice?
>
> Thanks.
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> http://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>