Sorry if this is a common question, can't find an answer.
I wonder if there is a generalisation of the Thread Safe proxies that are available for collections, those that make un-sinchronized collections synchronized.
Using AspectJ, it should be possible to write:
class ThreadSafeProxy
{
public static <T> T getInstance ( T unsinchronizedObject )
}
which would return an object where all the public methods of unsinchronizedObject would be intercepted and wrapped inside synchronize ( unsinchronizedObject ). Without AspectJ, it should be possible to write:
<T> T static synchronizeMethod ( Object unsynchObject, Class<T> returnType, String methodName, Object... params )
And implement it via reflection. Though this would be slower and probably less practical.
Thanks in advance for any help.