17 Jul 15:46
Re: [groovy-user] creating a new method inside invokeMethod
From: Graeme Rocher <graeme@...>
Subject: Re: [groovy-user] creating a new method inside invokeMethod
Newsgroups: gmane.comp.lang.groovy.user
Date: 2008-07-17 13:46:30 GMT
Subject: Re: [groovy-user] creating a new method inside invokeMethod
Newsgroups: gmane.comp.lang.groovy.user
Date: 2008-07-17 13:46:30 GMT
You shouldn't have to synchronize, Groovy uses concurrent implementations of collections under the surface. If you do get ConcurrentModificationExceptions it should be regarded as a bug, but since we use this technique for GORM in Grails if this were a problem we would know about it by now Cheers On Thu, Jul 17, 2008 at 2:38 PM, Rubee <charlestassoni@...> wrote: > > I've seen examples where invokeMethod creates a new method so that, on the > next call, the performance hit is reduced. Here's an example from Venkat > Subramaniam's excellent "Programming Groovy." (See p. 223.) > > class Manager > { > ....... > def methodMissing(String name, args) > { > println "intercepting call to $name..." > def delegateTo = null > > if(name.startsWith('simple')) { delegateTo = worker } > if(name.startsWith('advanced')) { delegateTo = expert } > > if (delegateTo?.metaClass.respondsTo(delegateTo, name, args)) > { > Manager.metaClass."${name}" = { Object[] varArgs -> > return delegateTo.invokeMethod(name, *varArgs) > } > > return delegateTo.invokeMethod(name, args) > } > > throw new MissingMethodException(name, Manager.class, args) > } > ........ > } //end class > > I need to do this is an webapp, which means my analog to the Manager class > shown here lives in a multi-threaded enviroment. > > My question, then, is how do I handle method-creation in a mulit-threaded > environment? I suppose that question boils down to: what do I need to > synchronize on, if anything? > > I hope developers are doing this kind of thing all the time, and maybe > someone can show me a real-world example. > > > > -- > View this message in context: http://www.nabble.com/creating-a-new-method-inside-invokeMethod-tp18508436p18508436.html > Sent from the groovy - user mailing list archive at Nabble.com. > > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > > -- -- Graeme Rocher Grails Project Lead G2One, Inc. Chief Technology Officer http://www.g2one.com --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
RSS Feed