Re: session state vs application state?

2007-09-27 Thread Peter Stavrinides
To be safe you need to use concurrent data structures, such as the 
concurrent hash map, and implement the class as a singleton.


Marcus wrote:

Josh,

Again, I agree, every method that change the _lista should be synchronized.

Marcus

  



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: session state vs application state?

2007-09-25 Thread Marcus
Josh,

Again, I agree, every method that change the _lista should be synchronized.

Marcus


Re: session state vs application state?

2007-09-25 Thread Josh Canfield
On 9/25/07, Marcus <[EMAIL PROTECTED]> wrote:
>
> Hi Josh,
>
> I agree with your comment. Add synchronization to "add" method is a good
> practice.
>
> Marcus
>

Synchronizing "add" won't solve the problem. Any time you are going to
structurally change the list then any iterator becomes invalid and will
fail-fast by throwing an exception.

Check out the java5 concurrent package for some thread safe data structures
http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/package-summary.html

-- 
--
TheDailyTube.com. Sign up and get the best new videos on the internet
delivered fresh to your inbox.


Re: session state vs application state?

2007-09-25 Thread Marcus
Hi Josh,

I agree with your comment. Add synchronization to "add" method is a good
practice.

Marcus


Re: session state vs application state?

2007-09-25 Thread Josh Canfield
I'm thinking that you are going to run into problems with this technique.
While page instances are thread safe, your page class will definitely be
used by multiple threads. If you are adding to _lista while iterating over
it then you are going to get an ConcurrentModificationException. Performing
actions on this list are going to require considering synchronization
issues.

Of course, this consideration is going to be required of any object that you
store at the application level (in the servlet context for instance) if you
are doing anything other than read only operations.

Josh


On 9/25/07, Marcus <[EMAIL PROTECTED]> wrote:
>
> Hi Robert,
>
> Anyway, if you create a class with static methods and attributes, your
> object will be shared for entire application.
>
> public class ListaEstatica {
>
>private static List _lista;
>
>public static List getLista() {
>if (_lista==null)
>_lista=new ArrayList(0);
>return _lista;
>}
>
>public static void add(Usuario usuario) { getLista().add(usuario);
> }
> }
>
>
> Marcus
>



-- 
--
TheDailyTube.com. Sign up and get the best new videos on the internet
delivered fresh to your inbox.


Re: session state vs application state?

2007-09-25 Thread Marcus
Hi Robert,

Anyway, if you create a class with static methods and attributes, your
object will be shared for entire application.

public class ListaEstatica {

private static List _lista;

public static List getLista() {
if (_lista==null)
_lista=new ArrayList(0);
return _lista;
}

public static void add(Usuario usuario) { getLista().add(usuario); }
}   


Marcus


Re: session state vs application state?

2007-09-24 Thread Howard Lewis Ship
You really want  your object to be stored in the ServletContext.  In
Tapestry terms, that would be possible as a new (as in, not yet provided by
the framework) ApplicationStatePersistenceStrategy.  Feel free to add a JIRA
Issue (and a patch!).

On 9/24/07, Robert A. Decker <[EMAIL PROTECTED]> wrote:
>
> I've read:
> http://tapestry.apache.org/tapestry5/tapestry-core/guide/appstate.html
>
> I understand that when using an ApplicationState it's really more of
> a Session state (the default way). What if I want to store something
> that's shared across all sessions as more of what I would think of as
> an ApplicationState? Do I just create a static variable somewhere?
>
> Sorry for the basic questions I've been asking. I'm new to Tapestry
> and still trying to figure out the standard ways of doing some basic
> stuff.
>
> R
>
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


-- 
Howard M. Lewis Ship
Partner and Senior Architect at Feature50

Creator Apache Tapestry and Apache HiveMind


session state vs application state?

2007-09-24 Thread Robert A. Decker

I've read:
http://tapestry.apache.org/tapestry5/tapestry-core/guide/appstate.html

I understand that when using an ApplicationState it's really more of  
a Session state (the default way). What if I want to store something  
that's shared across all sessions as more of what I would think of as  
an ApplicationState? Do I just create a static variable somewhere?


Sorry for the basic questions I've been asking. I'm new to Tapestry  
and still trying to figure out the standard ways of doing some basic  
stuff.


R

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]