You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Donyee <xy...@gmail.com> on 2007/10/17 16:21:51 UTC
[T5.06snap] About PERTHREAD_SCOPE?
I use "@Scope(PERTHREAD_SCOPE)" on build method in my AppModule.java.
It will create new instance in every new request, but it seems the method
build a singleton!
I use IE and FireFox request the page!
my code: in AppModule.java
@EagerLoad
@Scope(PERTHREAD_SCOPE)
public BoboCacheState buildCacheState(@InjectService("Cache")
Cache cache) {
BoboCacheState state = new BoboCacheState();
cache.getCacheEventNotificationService().registerListener(state);
return state;
}
in page index.java:
@Inject
private BoboCacheState state;
----徐 依伟
Re: [T5.06snap] About PERTHREAD_SCOPE?
Posted by Donyee <xy...@gmail.com>.
I use IE and Firefox to request the index page, the index page read data
from the BoboCachestate, and got defferent data!
They should be same!
2007/10/17, Howard Lewis Ship <hl...@gmail.com>:
>
> What makes you think that it builds a singleton?
>
> You will get a single proxy instance; internal to the proxy it
> finds/creates
> the per-thread instance.
>
> You need to be careful about the notification you have there; that will
> probably cause a leak of BoboCacheState instances.
>
> @Scope(PERTHREAD_SCOPE)
> public BoboCacheState buildCacheState(ThreadCleanupHub
> threadCleanupHub,
> @InjectService
> >
> > ("Cache")
> > Cache cache) {
> > final BoboCacheState state = new BoboCacheState();
> > cache.getCacheEventNotificationService
> ().registerListener(state);
>
>
> threadCleanupHub.addThreadCleanupListener(new
> ThreadCleanupListener() {
> public void threadDidCleanup() {
> cache.getCacheEventNotificationService
> ().unregisterListener(state);
> });
>
>
>
> return state;
> > }
>
>
>
>
> On 10/17/07, Donyee <xy...@gmail.com> wrote:
> >
> > I use "@Scope(PERTHREAD_SCOPE)" on build method in my AppModule.java.
> > It will create new instance in every new request, but it seems the
> method
> > build a singleton!
> > I use IE and FireFox request the page!
> > my code: in AppModule.java
> > @EagerLoad
> > @Scope(PERTHREAD_SCOPE)
> > public BoboCacheState buildCacheState(@InjectService("Cache")
> > Cache cache) {
> > BoboCacheState state = new BoboCacheState();
> > cache.getCacheEventNotificationService
> ().registerListener(state);
> > return state;
> > }
> > in page index.java:
> > @Inject
> > private BoboCacheState state;
> >
> >
> >
> > ----徐 依伟
> >
>
>
>
> --
> Howard M. Lewis Ship
> Partner and Senior Architect at Feature50
>
> Creator Apache Tapestry and Apache HiveMind
>
--
----徐 依伟
Re: [T5.06snap] About PERTHREAD_SCOPE?
Posted by Howard Lewis Ship <hl...@gmail.com>.
What makes you think that it builds a singleton?
You will get a single proxy instance; internal to the proxy it finds/creates
the per-thread instance.
You need to be careful about the notification you have there; that will
probably cause a leak of BoboCacheState instances.
@Scope(PERTHREAD_SCOPE)
public BoboCacheState buildCacheState(ThreadCleanupHub threadCleanupHub,
@InjectService
>
> ("Cache")
> Cache cache) {
> final BoboCacheState state = new BoboCacheState();
> cache.getCacheEventNotificationService().registerListener(state);
threadCleanupHub.addThreadCleanupListener(new
ThreadCleanupListener() {
public void threadDidCleanup() {
cache.getCacheEventNotificationService
().unregisterListener(state);
});
return state;
> }
On 10/17/07, Donyee <xy...@gmail.com> wrote:
>
> I use "@Scope(PERTHREAD_SCOPE)" on build method in my AppModule.java.
> It will create new instance in every new request, but it seems the method
> build a singleton!
> I use IE and FireFox request the page!
> my code: in AppModule.java
> @EagerLoad
> @Scope(PERTHREAD_SCOPE)
> public BoboCacheState buildCacheState(@InjectService("Cache")
> Cache cache) {
> BoboCacheState state = new BoboCacheState();
> cache.getCacheEventNotificationService().registerListener(state);
> return state;
> }
> in page index.java:
> @Inject
> private BoboCacheState state;
>
>
>
> ----徐 依伟
>
--
Howard M. Lewis Ship
Partner and Senior Architect at Feature50
Creator Apache Tapestry and Apache HiveMind