Yes, synchronisation can be treated as an aspect. Isn't the idea behind AOP to handle cross cutting concerns? Then, regarding synchronisation as a cross cutting concern can be handled via AOP without defining and using external libraries.
Consider the following example about read-write locking. Whenever an object is subject to be read/write, then you can capture the method and provide sufficient functionality for concurrency control.
public abstract aspect ReadWriteLockSynchronizationAspect
perthis(readOperations() || writeOperations()) {
public abstract pointcut readOperations();
public abstract pointcut writeOperations();
private ReadWriteLock _lock = new SomeReadWriteLock();
before() : readOperations() {
_lock.readLock().acquire();
}
after() : readOperations() {
_lock.readLock().release();
}
before() : writeOperations() {
_lock.writeLock().acquire();
}
after() : writeOperations() {
_lock.writeLock().release();
}
}
perthis
creates a new aspect for each read/write operation. Otherwise, only one aspect will be created and it works like a singleton object. For further information check AspectJ in Action.