IMHO, this might be a confusion/consistency thing. With guice-servlet, binding a servlet requires that it be bound in singleton scope, either explicitly or by annotation.
Note: Every servlet (or filter) is required to be a @Singleton. If you > cannot annotate the class directly, you must bind it using > bind(..).in(Singleton.class), separate to the filter() or servlet() rules. > Mapping under any other scope is an error. This is to maintain consistency > with the Servlet specification. Guice Servlet does not support the > deprecated SingleThreadModel. > http://code.google.com/p/google-guice/wiki/ServletModule It would make sense to be consistent for the method interceptor and require the same thing, this may reduce confusion. Cheers, -- TJ On Mon, Jan 24, 2011 at 9:20 AM, Fred Faber <[email protected]> wrote: > Hi again, > > I don't know that this is a defect, other than a case of needing to know > that an interceptor is a singleton. If its logic needs to be thread safe > then it can define mutexes appropriately. I don't know that I'd expect it > to behave any differently :/ > > -Fred > > > On Mon, Jan 24, 2011 at 10:17 AM, Anthony MULLER <[email protected] > > wrote: > >> Thanks very much for your reply. Do you know if this issue is tracked? >> >> Is it fixed in Guice 2.0? >> >> Regards, >> Anthony MÜLLER >> >> >> 2011/1/24 Fred Faber <[email protected]>: >> > Your suspicions are correct: an interceptor may be invoked by several >> > threads concurrently. For instance: >> > class TimingInterceptor implements MethodInterceptor { >> > private final Stopwatch stopwatch; >> > >> > TimingInterceptor(Stopwatch stopwatch) { >> > this.stopwatch = stopwatch; >> > } >> > @Override Object invoke(MethodInvocation i) throws Throwable { >> > stopwatch.reset(); >> > try { >> > return i.proceed(); >> > } finally { >> > System.err.println("Invocation time: " + stopwatch.get()); >> > } >> > } >> > Is going to break, because the stopwatch is shared among threads. >> > -Fred >> > On Mon, Jan 24, 2011 at 9:46 AM, Anthony MULLER < >> [email protected]> >> > wrote: >> >> >> >> Hello, >> >> >> >> I'm using "method interceptor" mechanisms with Guice 1.0 and I wish to >> >> know if it is thread-safe? (I have some strange behaviours in >> >> multithreading environment) >> >> >> >> Regards, >> >> Anthony MÜLLER >> >> >> >> -- >> >> You received this message because you are subscribed to the Google >> Groups >> >> "google-guice" group. >> >> To post to this group, send email to [email protected]. >> >> To unsubscribe from this group, send email to >> >> [email protected]<google-guice%[email protected]> >> . >> >> For more options, visit this group at >> >> http://groups.google.com/group/google-guice?hl=en. >> >> >> > >> > -- >> > You received this message because you are subscribed to the Google >> Groups >> > "google-guice" group. >> > To post to this group, send email to [email protected]. >> > To unsubscribe from this group, send email to >> > [email protected]<google-guice%[email protected]> >> . >> > For more options, visit this group at >> > http://groups.google.com/group/google-guice?hl=en. >> > >> >> -- >> You received this message because you are subscribed to the Google Groups >> "google-guice" group. >> To post to this group, send email to [email protected]. >> To unsubscribe from this group, send email to >> [email protected]<google-guice%[email protected]> >> . >> For more options, visit this group at >> http://groups.google.com/group/google-guice?hl=en. >> >> > -- > You received this message because you are subscribed to the Google Groups > "google-guice" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<google-guice%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/google-guice?hl=en. > -- You received this message because you are subscribed to the Google Groups "google-guice" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.
