Re: ThreadLocal not serialzable
Jonas Bonér <[email protected]> Sun, 04 May 2003 06:51:36 +0200
| Newsgroups | gmane.comp.java.aspectwerkz |
|---|---|
| Message-ID | <[email protected]> |
Hi Tom. This is not good. I havn't though of this (strange enough). There are two solutions that I can see. 1. Set the ThreadLocal fields to transient. Add a readObject method that sets these when the object is deserialized. I guess this is the most clean and correct way of handling this. But it needs to be done at transformation/load time. 2. Extend the ThreadLocal class (as you mentioned) to become serializable. The fastest solution but a bit of a hack. I don't know, I am unfortunately very busy at writing some other things for AspectWerkz right now. But I will take a look at this as soon as possible. Sorry about me being so narrow minded. Sincerely, Jonas. Ps. About the threadSafe="false" attribute. I had this implemented (and it didn't use ThreadLocal variables, so I guess it would have worked here) as a performance option. But since the performance gain was not very high and since turning the thread safety on/off could be misused or forgotten (resulting in the system not working) I decided to get rid of it (or actually commenting it out). Ds. Tom Miller wrote: > I did some thinking, read up some more on serialization, and read a > little more of the AspectWerkz source code. I discovered the > 'threadSafe="false"' attribute in <pointcut/> in one of the tests > (although I'm not clear whether that is appropriate with a perInstance > or perThread demployment model). > > So I tried using that, but now I'm getting: > java.io.NotSerializableException: java.lang.reflect.Method > presumably because the joinpoints are now "MemberMethodJoinPoint" > objects which contain java.lang.reflect.Method objects (not serializable). > > I've been thinking perhaps I should extend java.lang.reflect.Method, or > java.lang.ThreadLocal, and make it implement Serializable. > > But of course I'm open to any better advice. > > Thanks > Tom > > Tom Miller wrote: > >> Being my first post to this list, let me congratulate Jonas on a great >> framework! AspectWerkz is very nice to work with, and well thought >> out. I've been dinking around with the 0.4 examples and having some >> fair success with my own stuff. Although I've read a little, and have >> been to an AspectJ seminar, this is the first AOP programming I've >> done, and I like it very much. >> >> I've been working on a Prevayler-enabled persistence project which I'm >> aspectizing with AW. Looking at the decompiled persistent classes, I >> see that all of my setter functions, which have been given an Advice, >> have java.lang.ThreadLocal objects created for them. When Prevayler >> attempts to serialize these objects, I get a >> java.io.NotSerializableException: java.lang.ThreadLocal >> >> I hope there is some obvious solution which I'm just not seeing yet. >> Any ideas? >> >> TIA > > > -- Jonas http://freeroller.net/page/jboner ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf