You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Pablo Ruggia <pr...@gmail.com> on 2005/06/01 02:50:34 UTC

Re: ThreadLocal example pleeeeease!

Yes, it's possible.
Personally, I put this logic in setupForRequest method of my engine.
I created a class, UserContext, like this:

public class UserContext {

    static ThreadLocal _visitLocal = new ThreadLocal();

    public static Object getVisit() {
        return (Visit) _visitLocal.get();
    }

    public static void setVisit(Object visit) {
        _visitLocal.set(visit);
    }
}


And then, in setupForRequest:

protected void setupForRequest(RequestContext context) {
	if(getVisit() !=null)
            UserContext.setVisit(getVisit());
}

NOTE: getVisit() in baseEngine, do not create the visit object, like
the Page does.


So, anywhere you can put:

UserContext.getVisit().

The same you can do with Global object.

Let me know if that helped you.




On 5/31/05, Hensley, Richard <Ri...@mckesson.com> wrote:
> Sarah,
> 
> Do you have a Visit?
> 
> This sounds like session specific information that is normally stored in the
> Visit. I would consider constructing a method in my Visit that knows how to
> navigate the global object correctly.
> 
> -----Original Message-----
> From: sarah.simbad@women-at-work.org [mailto:sarah.simbad@women-at-work.org]
> 
> Sent: Tuesday, May 31, 2005 9:49 AM
> To: tapestry-user@jakarta.apache.org
> Subject: ThreadLocal example pleeeeease!
> 
> Could anyone of you post a quick example how to correctly
> use ThreadLocal within a Tapestry page and a Tapestry component?
> 
> My global object currently is a map of group data and the key is the group
> key. Different page getter methods need parameters that is derived from the
> group data .....
> 
> E.g. administrator is on:
> 
> admin.domain.com
> 
> moderators on moderators.domain.com
> 
> users on www.domain.com
> 
> guests on guests.domain.com
> 
> a method that is called getMenuOptions should retrieve the menu options.
> 
> The menu can contain 4 different kinds of data. So it is all in a global map
> and the database is only queried once.
> 
> But this leads to having to parse the map all the time
> the method getMenuOptions or any other method that will indirectly call it,
> is called.
> 
> and I want to sort of shift it into some sort of local variables to be able
> to directly access it.
> 
> Is that possible using ThreadLocal ? If so, how ?
> 
> Thank you!
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


RE: ThreadLocal example pleeeeease!

Posted by Patrick Casey <pa...@adelphia.net>.
	Can't you just make a method on the page e.g.

	Public Object getThingy(String key) {
		HashMap m = getAppropriateMap(key);
		Object rc = m.get(key);
		Return rc;
	}

	When whenever you need to use this functionality from within a
component you just do.

	Object thingy = getPage().getThingy(key);

	I guess I'm not really seeing what the problem is here. If a given
operation requires too many steps and you have to repeat it a lot, make a
method out of it and just call the method repeatedly instead of repeating
the same code over and over again, neh?

	--- Pat

> -----Original Message-----
> From: sarah.simbad@women-at-work.org [mailto:sarah.simbad@women-at-
> work.org]
> Sent: Thursday, June 02, 2005 7:20 AM
> To: Tapestry users
> Subject: Re: ThreadLocal example pleeeeease!
> 
> Imagine you are within a component.
> 
> You need to get the global object.
> Then you need to get the specific HashMap.
> Then you need to get the object from inside the HashMap.
> Then you need to call the method on the object to get the property
> you want to know.
> 
> These are too many steps, especially when you need it several times
> within a page as several components need to know this information several
> times. The components themselves are stupid and dont have a glue about
> other
> components within the same page. And tapestry also ignores the fact the
> components from the same page share the same page data if you read from
> the
> global object.
> 
> So I thought I could save lots of performance to store it within the page
> so
> I dont have to iterate through the objects and hashmaps all the time.....
> 
> 
> > --- Ursprüngliche Nachricht ---
> > Von: Andreas Andreou <an...@di.uoa.gr>
> > An: Tapestry users <ta...@jakarta.apache.org>
> > Betreff: Re: ThreadLocal example pleeeeease!
> > Datum: Thu, 02 Jun 2005 15:07:56 +0300
> >
> > Why can't you use a custom Global object and
> > initialize the map in its constructor (will only get invoked once)
> > ???
> >
> >
> > sarah.simbad@women-at-work.org wrote:
> >
> > >Thanks. Ok, I try again.
> > >
> > >The following assumptions are made:
> > >
> > >1. The number of groups can change on the database without having
> > >to change the java code. (It is not a problem to restart the web
> > application
> > >if that happens.)
> > >
> > >2. All the data is loaded on start-up, independent on how many members
> > are
> > >logged in.
> > >
> > >Right now I do it on  setupForRequest(RequestContext context)
> > >and store it in a HashMap The problem only is I need to parse the
> > >HashMap every time and hundreds of times for every page.
> > >
> > >Imagine the following situation:
> > >
> > >www.domain.com is the English version
> > >es.domain.com is the Spanish version
> > >
> > >(I know you can override the locale, but this is also a good example
> > >of "group specific data" without using the visit object
> > >
> > >
> > >The domain name would be the key of the HashMap.
> > >
> > >If you have lots of components on a page that need to know the language
> > >to use for the graphics or text and you dont think about it at all,
> > >you end up gettings hundreds of database queries for every page.
> > >
> > >If you use the HashMap approach you need to go through the HashMap
> > hundreds
> > >of times....I am looking for an easy way to "remember" the language and
> > for
> > >instance domain/group specific data....
> > >
> > >
> > >
> > >>--- Ursprüngliche Nachricht ---
> > >>Von: "Patrick Casey" <pa...@adelphia.net>
> > >>An: "'Tapestry users'" <ta...@jakarta.apache.org>
> > >>Betreff: RE: ThreadLocal example pleeeeease!
> > >>Datum: Wed, 1 Jun 2005 11:15:13 -0700
> > >>
> > >>
> > >>	Public static final fAList = new HashMap(10000);
> > >>	Public static final fBList = new HashMap(10000);
> > >>	Public static final fCList = new HashMap(10000);
> > >>
> > >>	Public Object getMember(String key) {
> > >>		If (isGroupA)
> > >>			Return fAList.get(key);
> > >>		Else if (isGroupB)
> > >>			Return fBList.get(key);
> > >>		Else if (isGroupC)
> > >>			Return fCList.get(key);
> > >>	}
> > >>
> > >>
> > >>
> > >>>-----Original Message-----
> > >>>From: sarah.simbad@women-at-work.org [mailto:sarah.simbad@women-at-
> > >>>work.org]
> > >>>Sent: Wednesday, June 01, 2005 11:03 AM
> > >>>To: Pablo Ruggia
> > >>>Cc: tapestry-user@jakarta.apache.org
> > >>>Subject: Re: ThreadLocal example pleeeeease!
> > >>>
> > >>>Thank you! The problem however is the following.
> > >>>
> > >>>Assuming I have 30,000 members online at the same time,
> > >>>10,000 belong to group A,
> > >>>10,000 belong to group B,
> > >>>and
> > >>>10,000 belong to group C.
> > >>>
> > >>>I would then keep in memory 10,000 instances of
> > >>>configuration data for group A people,
> > >>>10,000 for group B people data and 10,000 for group C people
> > >>>related data.
> > >>>
> > >>>I only want to have 1 instance of the data of group A in memory,
> > >>>1 for B and 1 for c.
> > >>>
> > >>>
> > >>>Assuming it is 1kbyte of data per configuration group data it would
> be
> > >>>
> > >>>
> > >>the
> > >>
> > >>
> > >>>difference between 3 kbytes in memory altogether as every group
> > >>>would share the data and 90 Mbytes where every single member of the
> > >>>
> > >>>
> > >>10,000
> > >>
> > >>
> > >>>people keeps copy of its group data.
> > >>>
> > >>>Do you know what I mean ?
> > >>>
> > >>>Sarah
> > >>>
> > >>>
> > >>>>--- Ursprüngliche Nachricht ---
> > >>>>Von: Pablo Ruggia <pr...@gmail.com>
> > >>>>An: Tapestry users <ta...@jakarta.apache.org>
> > >>>>Betreff: Re: ThreadLocal example pleeeeease!
> > >>>>Datum: Tue, 31 May 2005 21:50:34 -0300
> > >>>>
> > >>>>Yes, it's possible.
> > >>>>Personally, I put this logic in setupForRequest method of my engine.
> > >>>>I created a class, UserContext, like this:
> > >>>>
> > >>>>public class UserContext {
> > >>>>
> > >>>>    static ThreadLocal _visitLocal = new ThreadLocal();
> > >>>>
> > >>>>    public static Object getVisit() {
> > >>>>        return (Visit) _visitLocal.get();
> > >>>>    }
> > >>>>
> > >>>>    public static void setVisit(Object visit) {
> > >>>>        _visitLocal.set(visit);
> > >>>>    }
> > >>>>}
> > >>>>
> > >>>>
> > >>>>And then, in setupForRequest:
> > >>>>
> > >>>>protected void setupForRequest(RequestContext context) {
> > >>>>	if(getVisit() !=null)
> > >>>>            UserContext.setVisit(getVisit());
> > >>>>}
> > >>>>
> > >>>>NOTE: getVisit() in baseEngine, do not create the visit object, like
> > >>>>the Page does.
> > >>>>
> > >>>>
> > >>>>So, anywhere you can put:
> > >>>>
> > >>>>UserContext.getVisit().
> > >>>>
> > >>>>The same you can do with Global object.
> > >>>>
> > >>>>Let me know if that helped you.
> > >>>>
> > >>>>
> > >>>>
> > >>>>
> > >>>>On 5/31/05, Hensley, Richard <Ri...@mckesson.com> wrote:
> > >>>>
> > >>>>
> > >>>>>Sarah,
> > >>>>>
> > >>>>>Do you have a Visit?
> > >>>>>
> > >>>>>This sounds like session specific information that is normally
> > >>>>>
> > >>>>>
> > >>stored
> > >>
> > >>
> > >>>in
> > >>>
> > >>>
> > >>>>the
> > >>>>
> > >>>>
> > >>>>>Visit. I would consider constructing a method in my Visit that
> knows
> > >>>>>
> > >>>>>
> > >>>how
> > >>>
> > >>>
> > >>>>to
> > >>>>
> > >>>>
> > >>>>>navigate the global object correctly.
> > >>>>>
> > >>>>>-----Original Message-----
> > >>>>>From: sarah.simbad@women-at-work.org
> > >>>>>
> > >>>>>
> > >>>>[mailto:sarah.simbad@women-at-work.org]
> > >>>>
> > >>>>
> > >>>>>Sent: Tuesday, May 31, 2005 9:49 AM
> > >>>>>To: tapestry-user@jakarta.apache.org
> > >>>>>Subject: ThreadLocal example pleeeeease!
> > >>>>>
> > >>>>>Could anyone of you post a quick example how to correctly
> > >>>>>use ThreadLocal within a Tapestry page and a Tapestry component?
> > >>>>>
> > >>>>>My global object currently is a map of group data and the key is
> the
> > >>>>>
> > >>>>>
> > >>>>group
> > >>>>
> > >>>>
> > >>>>>key. Different page getter methods need parameters that is derived
> > >>>>>
> > >>>>>
> > >>>from
> > >>>
> > >>>
> > >>>>the
> > >>>>
> > >>>>
> > >>>>>group data .....
> > >>>>>
> > >>>>>E.g. administrator is on:
> > >>>>>
> > >>>>>admin.domain.com
> > >>>>>
> > >>>>>moderators on moderators.domain.com
> > >>>>>
> > >>>>>users on www.domain.com
> > >>>>>
> > >>>>>guests on guests.domain.com
> > >>>>>
> > >>>>>a method that is called getMenuOptions should retrieve the menu
> > >>>>>
> > >>>>>
> > >>>options.
> > >>>
> > >>>
> > >>>>>The menu can contain 4 different kinds of data. So it is all in a
> > >>>>>
> > >>>>>
> > >>>global
> > >>>
> > >>>
> > >>>>map
> > >>>>
> > >>>>
> > >>>>>and the database is only queried once.
> > >>>>>
> > >>>>>But this leads to having to parse the map all the time
> > >>>>>the method getMenuOptions or any other method that will indirectly
> > >>>>>
> > >>>>>
> > >>>call
> > >>>
> > >>>
> > >>>>it,
> > >>>>
> > >>>>
> > >>>>>is called.
> > >>>>>
> > >>>>>and I want to sort of shift it into some sort of local variables to
> > >>>>>
> > >>>>>
> > >>be
> > >>
> > >>
> > >>>>able
> > >>>>
> > >>>>
> > >>>>>to directly access it.
> > >>>>>
> > >>>>>Is that possible using ThreadLocal ? If so, how ?
> > >>>>>
> > >>>>>Thank you!
> > >>>>>
> > >>>>>
> > >>>>>
> > >>>>>
> > >>---------------------------------------------------------------------
> > >>
> > >>
> > >>>>>To unsubscribe, e-mail: tapestry-user-
> unsubscribe@jakarta.apache.org
> > >>>>>For additional commands, e-mail:
> > >>>>>
> > >>>>>
> > >>tapestry-user-help@jakarta.apache.org
> > >>
> > >>
> > >>>>>
> > >>>>>
> > >>>>>
> > >>---------------------------------------------------------------------
> > >>
> > >>
> > >>>>>To unsubscribe, e-mail: tapestry-user-
> unsubscribe@jakarta.apache.org
> > >>>>>For additional commands, e-mail:
> > >>>>>
> > >>>>>
> > >>tapestry-user-help@jakarta.apache.org
> > >>
> > >>
> > >>>>>
> > >>>>>
> > >>>>--------------------------------------------------------------------
> -
> > >>>>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > >>>>For additional commands, e-mail: tapestry-user-
> help@jakarta.apache.org
> > >>>>
> > >>>>
> > >>>>
> > >>>---------------------------------------------------------------------
> > >>>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > >>>For additional commands, e-mail: tapestry-user-
> help@jakarta.apache.org
> > >>>
> > >>>
> > >>
> > >>---------------------------------------------------------------------
> > >>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > >>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> > >>
> > >>
> > >>
> > >
> > >---------------------------------------------------------------------
> > >To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > >For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> > >
> > >
> > >
> > >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: ThreadLocal example pleeeeease!

Posted by sa...@women-at-work.org.
Imagine you are within a component.

You need to get the global object.
Then you need to get the specific HashMap.
Then you need to get the object from inside the HashMap.
Then you need to call the method on the object to get the property 
you want to know.

These are too many steps, especially when you need it several times
within a page as several components need to know this information several
times. The components themselves are stupid and dont have a glue about other
components within the same page. And tapestry also ignores the fact the
components from the same page share the same page data if you read from the
global object.

So I thought I could save lots of performance to store it within the page so
I dont have to iterate through the objects and hashmaps all the time.....


> --- Ursprüngliche Nachricht ---
> Von: Andreas Andreou <an...@di.uoa.gr>
> An: Tapestry users <ta...@jakarta.apache.org>
> Betreff: Re: ThreadLocal example pleeeeease!
> Datum: Thu, 02 Jun 2005 15:07:56 +0300
> 
> Why can't you use a custom Global object and
> initialize the map in its constructor (will only get invoked once)
> ???
> 
> 
> sarah.simbad@women-at-work.org wrote:
> 
> >Thanks. Ok, I try again.
> >
> >The following assumptions are made:
> >
> >1. The number of groups can change on the database without having
> >to change the java code. (It is not a problem to restart the web
> application
> >if that happens.)
> >
> >2. All the data is loaded on start-up, independent on how many members
> are
> >logged in.
> >
> >Right now I do it on  setupForRequest(RequestContext context)
> >and store it in a HashMap The problem only is I need to parse the
> >HashMap every time and hundreds of times for every page.
> >
> >Imagine the following situation:
> >
> >www.domain.com is the English version
> >es.domain.com is the Spanish version
> >
> >(I know you can override the locale, but this is also a good example
> >of "group specific data" without using the visit object
> >
> >
> >The domain name would be the key of the HashMap.
> >
> >If you have lots of components on a page that need to know the language
> >to use for the graphics or text and you dont think about it at all,
> >you end up gettings hundreds of database queries for every page.
> >
> >If you use the HashMap approach you need to go through the HashMap
> hundreds
> >of times....I am looking for an easy way to "remember" the language and
> for
> >instance domain/group specific data....
> >
> >  
> >
> >>--- Ursprüngliche Nachricht ---
> >>Von: "Patrick Casey" <pa...@adelphia.net>
> >>An: "'Tapestry users'" <ta...@jakarta.apache.org>
> >>Betreff: RE: ThreadLocal example pleeeeease!
> >>Datum: Wed, 1 Jun 2005 11:15:13 -0700
> >>
> >>
> >>	Public static final fAList = new HashMap(10000);
> >>	Public static final fBList = new HashMap(10000);
> >>	Public static final fCList = new HashMap(10000);
> >>
> >>	Public Object getMember(String key) {
> >>		If (isGroupA)
> >>			Return fAList.get(key);
> >>		Else if (isGroupB)
> >>			Return fBList.get(key);
> >>		Else if (isGroupC)
> >>			Return fCList.get(key);
> >>	}
> >>
> >>    
> >>
> >>>-----Original Message-----
> >>>From: sarah.simbad@women-at-work.org [mailto:sarah.simbad@women-at-
> >>>work.org]
> >>>Sent: Wednesday, June 01, 2005 11:03 AM
> >>>To: Pablo Ruggia
> >>>Cc: tapestry-user@jakarta.apache.org
> >>>Subject: Re: ThreadLocal example pleeeeease!
> >>>
> >>>Thank you! The problem however is the following.
> >>>
> >>>Assuming I have 30,000 members online at the same time,
> >>>10,000 belong to group A,
> >>>10,000 belong to group B,
> >>>and
> >>>10,000 belong to group C.
> >>>
> >>>I would then keep in memory 10,000 instances of
> >>>configuration data for group A people,
> >>>10,000 for group B people data and 10,000 for group C people
> >>>related data.
> >>>
> >>>I only want to have 1 instance of the data of group A in memory,
> >>>1 for B and 1 for c.
> >>>
> >>>
> >>>Assuming it is 1kbyte of data per configuration group data it would be
> >>>      
> >>>
> >>the
> >>    
> >>
> >>>difference between 3 kbytes in memory altogether as every group
> >>>would share the data and 90 Mbytes where every single member of the
> >>>      
> >>>
> >>10,000
> >>    
> >>
> >>>people keeps copy of its group data.
> >>>
> >>>Do you know what I mean ?
> >>>
> >>>Sarah
> >>>      
> >>>
> >>>>--- Ursprüngliche Nachricht ---
> >>>>Von: Pablo Ruggia <pr...@gmail.com>
> >>>>An: Tapestry users <ta...@jakarta.apache.org>
> >>>>Betreff: Re: ThreadLocal example pleeeeease!
> >>>>Datum: Tue, 31 May 2005 21:50:34 -0300
> >>>>
> >>>>Yes, it's possible.
> >>>>Personally, I put this logic in setupForRequest method of my engine.
> >>>>I created a class, UserContext, like this:
> >>>>
> >>>>public class UserContext {
> >>>>
> >>>>    static ThreadLocal _visitLocal = new ThreadLocal();
> >>>>
> >>>>    public static Object getVisit() {
> >>>>        return (Visit) _visitLocal.get();
> >>>>    }
> >>>>
> >>>>    public static void setVisit(Object visit) {
> >>>>        _visitLocal.set(visit);
> >>>>    }
> >>>>}
> >>>>
> >>>>
> >>>>And then, in setupForRequest:
> >>>>
> >>>>protected void setupForRequest(RequestContext context) {
> >>>>	if(getVisit() !=null)
> >>>>            UserContext.setVisit(getVisit());
> >>>>}
> >>>>
> >>>>NOTE: getVisit() in baseEngine, do not create the visit object, like
> >>>>the Page does.
> >>>>
> >>>>
> >>>>So, anywhere you can put:
> >>>>
> >>>>UserContext.getVisit().
> >>>>
> >>>>The same you can do with Global object.
> >>>>
> >>>>Let me know if that helped you.
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>On 5/31/05, Hensley, Richard <Ri...@mckesson.com> wrote:
> >>>>        
> >>>>
> >>>>>Sarah,
> >>>>>
> >>>>>Do you have a Visit?
> >>>>>
> >>>>>This sounds like session specific information that is normally
> >>>>>          
> >>>>>
> >>stored
> >>    
> >>
> >>>in
> >>>      
> >>>
> >>>>the
> >>>>        
> >>>>
> >>>>>Visit. I would consider constructing a method in my Visit that knows
> >>>>>          
> >>>>>
> >>>how
> >>>      
> >>>
> >>>>to
> >>>>        
> >>>>
> >>>>>navigate the global object correctly.
> >>>>>
> >>>>>-----Original Message-----
> >>>>>From: sarah.simbad@women-at-work.org
> >>>>>          
> >>>>>
> >>>>[mailto:sarah.simbad@women-at-work.org]
> >>>>        
> >>>>
> >>>>>Sent: Tuesday, May 31, 2005 9:49 AM
> >>>>>To: tapestry-user@jakarta.apache.org
> >>>>>Subject: ThreadLocal example pleeeeease!
> >>>>>
> >>>>>Could anyone of you post a quick example how to correctly
> >>>>>use ThreadLocal within a Tapestry page and a Tapestry component?
> >>>>>
> >>>>>My global object currently is a map of group data and the key is the
> >>>>>          
> >>>>>
> >>>>group
> >>>>        
> >>>>
> >>>>>key. Different page getter methods need parameters that is derived
> >>>>>          
> >>>>>
> >>>from
> >>>      
> >>>
> >>>>the
> >>>>        
> >>>>
> >>>>>group data .....
> >>>>>
> >>>>>E.g. administrator is on:
> >>>>>
> >>>>>admin.domain.com
> >>>>>
> >>>>>moderators on moderators.domain.com
> >>>>>
> >>>>>users on www.domain.com
> >>>>>
> >>>>>guests on guests.domain.com
> >>>>>
> >>>>>a method that is called getMenuOptions should retrieve the menu
> >>>>>          
> >>>>>
> >>>options.
> >>>      
> >>>
> >>>>>The menu can contain 4 different kinds of data. So it is all in a
> >>>>>          
> >>>>>
> >>>global
> >>>      
> >>>
> >>>>map
> >>>>        
> >>>>
> >>>>>and the database is only queried once.
> >>>>>
> >>>>>But this leads to having to parse the map all the time
> >>>>>the method getMenuOptions or any other method that will indirectly
> >>>>>          
> >>>>>
> >>>call
> >>>      
> >>>
> >>>>it,
> >>>>        
> >>>>
> >>>>>is called.
> >>>>>
> >>>>>and I want to sort of shift it into some sort of local variables to
> >>>>>          
> >>>>>
> >>be
> >>    
> >>
> >>>>able
> >>>>        
> >>>>
> >>>>>to directly access it.
> >>>>>
> >>>>>Is that possible using ThreadLocal ? If so, how ?
> >>>>>
> >>>>>Thank you!
> >>>>>
> >>>>>
> >>>>>          
> >>>>>
> >>---------------------------------------------------------------------
> >>    
> >>
> >>>>>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> >>>>>For additional commands, e-mail:
> >>>>>          
> >>>>>
> >>tapestry-user-help@jakarta.apache.org
> >>    
> >>
> >>>>>
> >>>>>          
> >>>>>
> >>---------------------------------------------------------------------
> >>    
> >>
> >>>>>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> >>>>>For additional commands, e-mail:
> >>>>>          
> >>>>>
> >>tapestry-user-help@jakarta.apache.org
> >>    
> >>
> >>>>>          
> >>>>>
> >>>>---------------------------------------------------------------------
> >>>>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> >>>>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> >>>>
> >>>>        
> >>>>
> >>>---------------------------------------------------------------------
> >>>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> >>>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> >>>      
> >>>
> >>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> >>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> >>
> >>    
> >>
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> >
> >
> >  
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: ThreadLocal example pleeeeease!

Posted by Andreas Andreou <an...@di.uoa.gr>.
Why can't you use a custom Global object and
initialize the map in its constructor (will only get invoked once)
???


sarah.simbad@women-at-work.org wrote:

>Thanks. Ok, I try again.
>
>The following assumptions are made:
>
>1. The number of groups can change on the database without having
>to change the java code. (It is not a problem to restart the web application
>if that happens.)
>
>2. All the data is loaded on start-up, independent on how many members are
>logged in.
>
>Right now I do it on  setupForRequest(RequestContext context)
>and store it in a HashMap The problem only is I need to parse the
>HashMap every time and hundreds of times for every page.
>
>Imagine the following situation:
>
>www.domain.com is the English version
>es.domain.com is the Spanish version
>
>(I know you can override the locale, but this is also a good example
>of "group specific data" without using the visit object
>
>
>The domain name would be the key of the HashMap.
>
>If you have lots of components on a page that need to know the language
>to use for the graphics or text and you dont think about it at all,
>you end up gettings hundreds of database queries for every page.
>
>If you use the HashMap approach you need to go through the HashMap hundreds
>of times....I am looking for an easy way to "remember" the language and for
>instance domain/group specific data....
>
>  
>
>>--- Ursprüngliche Nachricht ---
>>Von: "Patrick Casey" <pa...@adelphia.net>
>>An: "'Tapestry users'" <ta...@jakarta.apache.org>
>>Betreff: RE: ThreadLocal example pleeeeease!
>>Datum: Wed, 1 Jun 2005 11:15:13 -0700
>>
>>
>>	Public static final fAList = new HashMap(10000);
>>	Public static final fBList = new HashMap(10000);
>>	Public static final fCList = new HashMap(10000);
>>
>>	Public Object getMember(String key) {
>>		If (isGroupA)
>>			Return fAList.get(key);
>>		Else if (isGroupB)
>>			Return fBList.get(key);
>>		Else if (isGroupC)
>>			Return fCList.get(key);
>>	}
>>
>>    
>>
>>>-----Original Message-----
>>>From: sarah.simbad@women-at-work.org [mailto:sarah.simbad@women-at-
>>>work.org]
>>>Sent: Wednesday, June 01, 2005 11:03 AM
>>>To: Pablo Ruggia
>>>Cc: tapestry-user@jakarta.apache.org
>>>Subject: Re: ThreadLocal example pleeeeease!
>>>
>>>Thank you! The problem however is the following.
>>>
>>>Assuming I have 30,000 members online at the same time,
>>>10,000 belong to group A,
>>>10,000 belong to group B,
>>>and
>>>10,000 belong to group C.
>>>
>>>I would then keep in memory 10,000 instances of
>>>configuration data for group A people,
>>>10,000 for group B people data and 10,000 for group C people
>>>related data.
>>>
>>>I only want to have 1 instance of the data of group A in memory,
>>>1 for B and 1 for c.
>>>
>>>
>>>Assuming it is 1kbyte of data per configuration group data it would be
>>>      
>>>
>>the
>>    
>>
>>>difference between 3 kbytes in memory altogether as every group
>>>would share the data and 90 Mbytes where every single member of the
>>>      
>>>
>>10,000
>>    
>>
>>>people keeps copy of its group data.
>>>
>>>Do you know what I mean ?
>>>
>>>Sarah
>>>      
>>>
>>>>--- Ursprüngliche Nachricht ---
>>>>Von: Pablo Ruggia <pr...@gmail.com>
>>>>An: Tapestry users <ta...@jakarta.apache.org>
>>>>Betreff: Re: ThreadLocal example pleeeeease!
>>>>Datum: Tue, 31 May 2005 21:50:34 -0300
>>>>
>>>>Yes, it's possible.
>>>>Personally, I put this logic in setupForRequest method of my engine.
>>>>I created a class, UserContext, like this:
>>>>
>>>>public class UserContext {
>>>>
>>>>    static ThreadLocal _visitLocal = new ThreadLocal();
>>>>
>>>>    public static Object getVisit() {
>>>>        return (Visit) _visitLocal.get();
>>>>    }
>>>>
>>>>    public static void setVisit(Object visit) {
>>>>        _visitLocal.set(visit);
>>>>    }
>>>>}
>>>>
>>>>
>>>>And then, in setupForRequest:
>>>>
>>>>protected void setupForRequest(RequestContext context) {
>>>>	if(getVisit() !=null)
>>>>            UserContext.setVisit(getVisit());
>>>>}
>>>>
>>>>NOTE: getVisit() in baseEngine, do not create the visit object, like
>>>>the Page does.
>>>>
>>>>
>>>>So, anywhere you can put:
>>>>
>>>>UserContext.getVisit().
>>>>
>>>>The same you can do with Global object.
>>>>
>>>>Let me know if that helped you.
>>>>
>>>>
>>>>
>>>>
>>>>On 5/31/05, Hensley, Richard <Ri...@mckesson.com> wrote:
>>>>        
>>>>
>>>>>Sarah,
>>>>>
>>>>>Do you have a Visit?
>>>>>
>>>>>This sounds like session specific information that is normally
>>>>>          
>>>>>
>>stored
>>    
>>
>>>in
>>>      
>>>
>>>>the
>>>>        
>>>>
>>>>>Visit. I would consider constructing a method in my Visit that knows
>>>>>          
>>>>>
>>>how
>>>      
>>>
>>>>to
>>>>        
>>>>
>>>>>navigate the global object correctly.
>>>>>
>>>>>-----Original Message-----
>>>>>From: sarah.simbad@women-at-work.org
>>>>>          
>>>>>
>>>>[mailto:sarah.simbad@women-at-work.org]
>>>>        
>>>>
>>>>>Sent: Tuesday, May 31, 2005 9:49 AM
>>>>>To: tapestry-user@jakarta.apache.org
>>>>>Subject: ThreadLocal example pleeeeease!
>>>>>
>>>>>Could anyone of you post a quick example how to correctly
>>>>>use ThreadLocal within a Tapestry page and a Tapestry component?
>>>>>
>>>>>My global object currently is a map of group data and the key is the
>>>>>          
>>>>>
>>>>group
>>>>        
>>>>
>>>>>key. Different page getter methods need parameters that is derived
>>>>>          
>>>>>
>>>from
>>>      
>>>
>>>>the
>>>>        
>>>>
>>>>>group data .....
>>>>>
>>>>>E.g. administrator is on:
>>>>>
>>>>>admin.domain.com
>>>>>
>>>>>moderators on moderators.domain.com
>>>>>
>>>>>users on www.domain.com
>>>>>
>>>>>guests on guests.domain.com
>>>>>
>>>>>a method that is called getMenuOptions should retrieve the menu
>>>>>          
>>>>>
>>>options.
>>>      
>>>
>>>>>The menu can contain 4 different kinds of data. So it is all in a
>>>>>          
>>>>>
>>>global
>>>      
>>>
>>>>map
>>>>        
>>>>
>>>>>and the database is only queried once.
>>>>>
>>>>>But this leads to having to parse the map all the time
>>>>>the method getMenuOptions or any other method that will indirectly
>>>>>          
>>>>>
>>>call
>>>      
>>>
>>>>it,
>>>>        
>>>>
>>>>>is called.
>>>>>
>>>>>and I want to sort of shift it into some sort of local variables to
>>>>>          
>>>>>
>>be
>>    
>>
>>>>able
>>>>        
>>>>
>>>>>to directly access it.
>>>>>
>>>>>Is that possible using ThreadLocal ? If so, how ?
>>>>>
>>>>>Thank you!
>>>>>
>>>>>
>>>>>          
>>>>>
>>---------------------------------------------------------------------
>>    
>>
>>>>>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>>>>>For additional commands, e-mail:
>>>>>          
>>>>>
>>tapestry-user-help@jakarta.apache.org
>>    
>>
>>>>>
>>>>>          
>>>>>
>>---------------------------------------------------------------------
>>    
>>
>>>>>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>>>>>For additional commands, e-mail:
>>>>>          
>>>>>
>>tapestry-user-help@jakarta.apache.org
>>    
>>
>>>>>          
>>>>>
>>>>---------------------------------------------------------------------
>>>>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>>>>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>>>
>>>>        
>>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>>>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>>      
>>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>
>>    
>>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
>  
>


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


RE: ThreadLocal example pleeeeease!

Posted by sa...@women-at-work.org.
Thanks. Ok, I try again.

The following assumptions are made:

1. The number of groups can change on the database without having
to change the java code. (It is not a problem to restart the web application
if that happens.)

2. All the data is loaded on start-up, independent on how many members are
logged in.

Right now I do it on  setupForRequest(RequestContext context)
and store it in a HashMap The problem only is I need to parse the
HashMap every time and hundreds of times for every page.

Imagine the following situation:

www.domain.com is the English version
es.domain.com is the Spanish version

(I know you can override the locale, but this is also a good example
of "group specific data" without using the visit object


The domain name would be the key of the HashMap.

If you have lots of components on a page that need to know the language
to use for the graphics or text and you dont think about it at all,
you end up gettings hundreds of database queries for every page.

If you use the HashMap approach you need to go through the HashMap hundreds
of times....I am looking for an easy way to "remember" the language and for
instance domain/group specific data....

> --- Ursprüngliche Nachricht ---
> Von: "Patrick Casey" <pa...@adelphia.net>
> An: "'Tapestry users'" <ta...@jakarta.apache.org>
> Betreff: RE: ThreadLocal example pleeeeease!
> Datum: Wed, 1 Jun 2005 11:15:13 -0700
> 
> 
> 	Public static final fAList = new HashMap(10000);
> 	Public static final fBList = new HashMap(10000);
> 	Public static final fCList = new HashMap(10000);
> 
> 	Public Object getMember(String key) {
> 		If (isGroupA)
> 			Return fAList.get(key);
> 		Else if (isGroupB)
> 			Return fBList.get(key);
> 		Else if (isGroupC)
> 			Return fCList.get(key);
> 	}
> 
> > -----Original Message-----
> > From: sarah.simbad@women-at-work.org [mailto:sarah.simbad@women-at-
> > work.org]
> > Sent: Wednesday, June 01, 2005 11:03 AM
> > To: Pablo Ruggia
> > Cc: tapestry-user@jakarta.apache.org
> > Subject: Re: ThreadLocal example pleeeeease!
> > 
> > Thank you! The problem however is the following.
> > 
> > Assuming I have 30,000 members online at the same time,
> > 10,000 belong to group A,
> > 10,000 belong to group B,
> > and
> > 10,000 belong to group C.
> > 
> > I would then keep in memory 10,000 instances of
> > configuration data for group A people,
> > 10,000 for group B people data and 10,000 for group C people
> > related data.
> > 
> > I only want to have 1 instance of the data of group A in memory,
> > 1 for B and 1 for c.
> > 
> > 
> > Assuming it is 1kbyte of data per configuration group data it would be
> the
> > difference between 3 kbytes in memory altogether as every group
> > would share the data and 90 Mbytes where every single member of the
> 10,000
> > people keeps copy of its group data.
> > 
> > Do you know what I mean ?
> > 
> > Sarah
> > > --- Ursprüngliche Nachricht ---
> > > Von: Pablo Ruggia <pr...@gmail.com>
> > > An: Tapestry users <ta...@jakarta.apache.org>
> > > Betreff: Re: ThreadLocal example pleeeeease!
> > > Datum: Tue, 31 May 2005 21:50:34 -0300
> > >
> > > Yes, it's possible.
> > > Personally, I put this logic in setupForRequest method of my engine.
> > > I created a class, UserContext, like this:
> > >
> > > public class UserContext {
> > >
> > >     static ThreadLocal _visitLocal = new ThreadLocal();
> > >
> > >     public static Object getVisit() {
> > >         return (Visit) _visitLocal.get();
> > >     }
> > >
> > >     public static void setVisit(Object visit) {
> > >         _visitLocal.set(visit);
> > >     }
> > > }
> > >
> > >
> > > And then, in setupForRequest:
> > >
> > > protected void setupForRequest(RequestContext context) {
> > > 	if(getVisit() !=null)
> > >             UserContext.setVisit(getVisit());
> > > }
> > >
> > > NOTE: getVisit() in baseEngine, do not create the visit object, like
> > > the Page does.
> > >
> > >
> > > So, anywhere you can put:
> > >
> > > UserContext.getVisit().
> > >
> > > The same you can do with Global object.
> > >
> > > Let me know if that helped you.
> > >
> > >
> > >
> > >
> > > On 5/31/05, Hensley, Richard <Ri...@mckesson.com> wrote:
> > > > Sarah,
> > > >
> > > > Do you have a Visit?
> > > >
> > > > This sounds like session specific information that is normally
> stored
> > in
> > > the
> > > > Visit. I would consider constructing a method in my Visit that knows
> > how
> > > to
> > > > navigate the global object correctly.
> > > >
> > > > -----Original Message-----
> > > > From: sarah.simbad@women-at-work.org
> > > [mailto:sarah.simbad@women-at-work.org]
> > > >
> > > > Sent: Tuesday, May 31, 2005 9:49 AM
> > > > To: tapestry-user@jakarta.apache.org
> > > > Subject: ThreadLocal example pleeeeease!
> > > >
> > > > Could anyone of you post a quick example how to correctly
> > > > use ThreadLocal within a Tapestry page and a Tapestry component?
> > > >
> > > > My global object currently is a map of group data and the key is the
> > > group
> > > > key. Different page getter methods need parameters that is derived
> > from
> > > the
> > > > group data .....
> > > >
> > > > E.g. administrator is on:
> > > >
> > > > admin.domain.com
> > > >
> > > > moderators on moderators.domain.com
> > > >
> > > > users on www.domain.com
> > > >
> > > > guests on guests.domain.com
> > > >
> > > > a method that is called getMenuOptions should retrieve the menu
> > options.
> > > >
> > > > The menu can contain 4 different kinds of data. So it is all in a
> > global
> > > map
> > > > and the database is only queried once.
> > > >
> > > > But this leads to having to parse the map all the time
> > > > the method getMenuOptions or any other method that will indirectly
> > call
> > > it,
> > > > is called.
> > > >
> > > > and I want to sort of shift it into some sort of local variables to
> be
> > > able
> > > > to directly access it.
> > > >
> > > > Is that possible using ThreadLocal ? If so, how ?
> > > >
> > > > Thank you!
> > > >
> > > >
> ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > > > For additional commands, e-mail:
> tapestry-user-help@jakarta.apache.org
> > > >
> > > >
> > > >
> ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > > > For additional commands, e-mail:
> tapestry-user-help@jakarta.apache.org
> > > >
> > > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> > >
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


RE: ThreadLocal example pleeeeease!

Posted by Patrick Casey <pa...@adelphia.net>.
	Public static final fAList = new HashMap(10000);
	Public static final fBList = new HashMap(10000);
	Public static final fCList = new HashMap(10000);

	Public Object getMember(String key) {
		If (isGroupA)
			Return fAList.get(key);
		Else if (isGroupB)
			Return fBList.get(key);
		Else if (isGroupC)
			Return fCList.get(key);
	}

> -----Original Message-----
> From: sarah.simbad@women-at-work.org [mailto:sarah.simbad@women-at-
> work.org]
> Sent: Wednesday, June 01, 2005 11:03 AM
> To: Pablo Ruggia
> Cc: tapestry-user@jakarta.apache.org
> Subject: Re: ThreadLocal example pleeeeease!
> 
> Thank you! The problem however is the following.
> 
> Assuming I have 30,000 members online at the same time,
> 10,000 belong to group A,
> 10,000 belong to group B,
> and
> 10,000 belong to group C.
> 
> I would then keep in memory 10,000 instances of
> configuration data for group A people,
> 10,000 for group B people data and 10,000 for group C people
> related data.
> 
> I only want to have 1 instance of the data of group A in memory,
> 1 for B and 1 for c.
> 
> 
> Assuming it is 1kbyte of data per configuration group data it would be the
> difference between 3 kbytes in memory altogether as every group
> would share the data and 90 Mbytes where every single member of the 10,000
> people keeps copy of its group data.
> 
> Do you know what I mean ?
> 
> Sarah
> > --- Ursprüngliche Nachricht ---
> > Von: Pablo Ruggia <pr...@gmail.com>
> > An: Tapestry users <ta...@jakarta.apache.org>
> > Betreff: Re: ThreadLocal example pleeeeease!
> > Datum: Tue, 31 May 2005 21:50:34 -0300
> >
> > Yes, it's possible.
> > Personally, I put this logic in setupForRequest method of my engine.
> > I created a class, UserContext, like this:
> >
> > public class UserContext {
> >
> >     static ThreadLocal _visitLocal = new ThreadLocal();
> >
> >     public static Object getVisit() {
> >         return (Visit) _visitLocal.get();
> >     }
> >
> >     public static void setVisit(Object visit) {
> >         _visitLocal.set(visit);
> >     }
> > }
> >
> >
> > And then, in setupForRequest:
> >
> > protected void setupForRequest(RequestContext context) {
> > 	if(getVisit() !=null)
> >             UserContext.setVisit(getVisit());
> > }
> >
> > NOTE: getVisit() in baseEngine, do not create the visit object, like
> > the Page does.
> >
> >
> > So, anywhere you can put:
> >
> > UserContext.getVisit().
> >
> > The same you can do with Global object.
> >
> > Let me know if that helped you.
> >
> >
> >
> >
> > On 5/31/05, Hensley, Richard <Ri...@mckesson.com> wrote:
> > > Sarah,
> > >
> > > Do you have a Visit?
> > >
> > > This sounds like session specific information that is normally stored
> in
> > the
> > > Visit. I would consider constructing a method in my Visit that knows
> how
> > to
> > > navigate the global object correctly.
> > >
> > > -----Original Message-----
> > > From: sarah.simbad@women-at-work.org
> > [mailto:sarah.simbad@women-at-work.org]
> > >
> > > Sent: Tuesday, May 31, 2005 9:49 AM
> > > To: tapestry-user@jakarta.apache.org
> > > Subject: ThreadLocal example pleeeeease!
> > >
> > > Could anyone of you post a quick example how to correctly
> > > use ThreadLocal within a Tapestry page and a Tapestry component?
> > >
> > > My global object currently is a map of group data and the key is the
> > group
> > > key. Different page getter methods need parameters that is derived
> from
> > the
> > > group data .....
> > >
> > > E.g. administrator is on:
> > >
> > > admin.domain.com
> > >
> > > moderators on moderators.domain.com
> > >
> > > users on www.domain.com
> > >
> > > guests on guests.domain.com
> > >
> > > a method that is called getMenuOptions should retrieve the menu
> options.
> > >
> > > The menu can contain 4 different kinds of data. So it is all in a
> global
> > map
> > > and the database is only queried once.
> > >
> > > But this leads to having to parse the map all the time
> > > the method getMenuOptions or any other method that will indirectly
> call
> > it,
> > > is called.
> > >
> > > and I want to sort of shift it into some sort of local variables to be
> > able
> > > to directly access it.
> > >
> > > Is that possible using ThreadLocal ? If so, how ?
> > >
> > > Thank you!
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: ThreadLocal example pleeeeease!

Posted by sa...@women-at-work.org.
Thank you! The problem however is the following.

Assuming I have 30,000 members online at the same time,
10,000 belong to group A,
10,000 belong to group B,
and 
10,000 belong to group C.

I would then keep in memory 10,000 instances of 
configuration data for group A people,
10,000 for group B people data and 10,000 for group C people
related data.

I only want to have 1 instance of the data of group A in memory,
1 for B and 1 for c.


Assuming it is 1kbyte of data per configuration group data it would be the
difference between 3 kbytes in memory altogether as every group
would share the data and 90 Mbytes where every single member of the 10,000
people keeps copy of its group data.

Do you know what I mean ?

Sarah
> --- Ursprüngliche Nachricht ---
> Von: Pablo Ruggia <pr...@gmail.com>
> An: Tapestry users <ta...@jakarta.apache.org>
> Betreff: Re: ThreadLocal example pleeeeease!
> Datum: Tue, 31 May 2005 21:50:34 -0300
> 
> Yes, it's possible.
> Personally, I put this logic in setupForRequest method of my engine.
> I created a class, UserContext, like this:
> 
> public class UserContext {
> 
>     static ThreadLocal _visitLocal = new ThreadLocal();
> 
>     public static Object getVisit() {
>         return (Visit) _visitLocal.get();
>     }
> 
>     public static void setVisit(Object visit) {
>         _visitLocal.set(visit);
>     }
> }
> 
> 
> And then, in setupForRequest:
> 
> protected void setupForRequest(RequestContext context) {
> 	if(getVisit() !=null)
>             UserContext.setVisit(getVisit());
> }
> 
> NOTE: getVisit() in baseEngine, do not create the visit object, like
> the Page does.
> 
> 
> So, anywhere you can put:
> 
> UserContext.getVisit().
> 
> The same you can do with Global object.
> 
> Let me know if that helped you.
> 
> 
> 
> 
> On 5/31/05, Hensley, Richard <Ri...@mckesson.com> wrote:
> > Sarah,
> > 
> > Do you have a Visit?
> > 
> > This sounds like session specific information that is normally stored in
> the
> > Visit. I would consider constructing a method in my Visit that knows how
> to
> > navigate the global object correctly.
> > 
> > -----Original Message-----
> > From: sarah.simbad@women-at-work.org
> [mailto:sarah.simbad@women-at-work.org]
> > 
> > Sent: Tuesday, May 31, 2005 9:49 AM
> > To: tapestry-user@jakarta.apache.org
> > Subject: ThreadLocal example pleeeeease!
> > 
> > Could anyone of you post a quick example how to correctly
> > use ThreadLocal within a Tapestry page and a Tapestry component?
> > 
> > My global object currently is a map of group data and the key is the
> group
> > key. Different page getter methods need parameters that is derived from
> the
> > group data .....
> > 
> > E.g. administrator is on:
> > 
> > admin.domain.com
> > 
> > moderators on moderators.domain.com
> > 
> > users on www.domain.com
> > 
> > guests on guests.domain.com
> > 
> > a method that is called getMenuOptions should retrieve the menu options.
> > 
> > The menu can contain 4 different kinds of data. So it is all in a global
> map
> > and the database is only queried once.
> > 
> > But this leads to having to parse the map all the time
> > the method getMenuOptions or any other method that will indirectly call
> it,
> > is called.
> > 
> > and I want to sort of shift it into some sort of local variables to be
> able
> > to directly access it.
> > 
> > Is that possible using ThreadLocal ? If so, how ?
> > 
> > Thank you!
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> > 
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org