Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    EJB stateful e EJB stateless

    Salve raga,
    per capire la differenza EJB stateful e stateless ho fatto il seguente esempio:

    Ho creato 2 EJB
    entrambi hanno 2 metodi:
    int getCounter()
    {
    return counter
    }
    void addCounter()
    {
    counter++
    }
    e possiedono la variabile intera counter

    in una action di struts viene richiamato prima l'addCounter e poi getCounter

    io mi aspetto:
    per lo stateless tutti i client utilizzano stessa istanza dell'ejb quindi due client diversi usano lo stesso counter

    client A chiama action e vede 1
    client B chiama action e vede 2
    client A chiama action e vede 3

    per lo stateful invece l'istanza deve essere relativa al client quindi:
    client A chiama action e vede 1
    client B chiama action e vede 1
    client A chiama action e vede 2
    client A chiama action e vede 3
    client B chiama action e vede 2

    correggetemi se sbaglio...

    il problema è che lo statefull mi restituisce sempre 1!!!

    Consigli?

    Grazie

  2. #2
    Moderatore di Programmazione L'avatar di alka
    Registrato dal
    Oct 2001
    residenza
    Reggio Emilia
    Messaggi
    24,472

    Moderazione

    Le domande relative al linguaggio Java vanno ora inserite nell'apposito forum dedicato.
    Sposto la discussione.

    Ciao!
    MARCO BREVEGLIERI
    Software and Web Developer, Teacher and Consultant

    Home | Blog | Delphi Podcast | Twitch | Altro...

  3. #3
    Utente di HTML.it L'avatar di blueice
    Registrato dal
    Feb 2001
    Messaggi
    121
    Quello che ti risponde sempre 1 è uno stateless. L'altro è uno stateful.

    Ti riporto le specifiche della SUN di seguito :

    - Stateless Session Beans

    A stateless session bean does not maintain a conversational state for the client. When a client invokes the method of a stateless bean, the bean's instance variables may contain a state, but only for the duration of the invocation. When the method is finished, the state is no longer retained. Except during method invocation, all instances of a stateless bean are equivalent, allowing the EJB container to assign an instance to any client.


    Because stateless session beans can support multiple clients, they can offer better scalability for applications that require large numbers of clients. Typically, an application requires fewer stateless session beans than stateful session beans to support the same number of clients.

    At times, the EJB container may write a stateful session bean to secondary storage. However, stateless session beans are never written to secondary storage. Therefore, stateless beans may offer better performance than stateful beans.

    A stateless session bean can implement a web service, but other types of enterprise beans cannot.

    - Stateful Session Beans

    The state of an object consists of the values of its instance variables. In a stateful session bean, the instance variables represent the state of a unique client-bean session. Because the client interacts ("talks") with its bean, this state is often called the conversational state.


    The state is retained for the duration of the client-bean session. If the client removes the bean or terminates, the session ends and the state disappears. This transient nature of the state is not a problem, however, because when the conversation between the client and the bean ends there is no need to retain the state.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.