Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8039675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:38:54+00:00 2026-06-05T03:38:54+00:00

I am building a small Poker app to work on my java skills. I

  • 0

I am building a small Poker app to work on my java skills. I am creating it in Texas Hold’em format.

Basically I want to maintain the hand state in a servlet that handles my AJAX responses. I am guessing the member variable in a servlet is not safe, whereas the session should be. Could you please explain the correct implementation of this solution?

public class PokerClientResponse extends HttpServlet {
private static Logger LOG = Logger.getLogger(PokerClientResponse.class);

private static final long serialVersionUID = 1L;
private HandState handState = null;

public PokerClientResponse() {
    super();
}

protected void doGet(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {
            //Which is the best way to maintain hand state?

    //Get the State from the session, then increment it
    HttpSession session = request.getSession();
    Object obj = session.getAttribute("handState");

            //Advance the Hand State
    getHandState().goToNextState();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T03:38:55+00:00Added an answer on June 5, 2026 at 3:38 am

    A servlet instance variable (unless it’s a ThreadLocal is indeed not safe, because there is only a single servlet instance serving all request made to its mapping.

    All you need to do is save/load the hand state from the session, which is unique per user conversation1. Remove the hand state instance variable.

    Remove the hand state getter. Only deal with hand state inside the request processing call, and pass that hand state to other methods that need it (if any).

    Your code would be closer to this:

    protected void doGet(etc) {
        HandState state = (HandState) request.getSession().getAttribute("handState");
        state.nextState();
    }
    

    Although I recommend using a constant for the session attribute key.


    1 Which is different from unique per browser window or tab; if you have multiple windows or tabs open, they may be sharing the same session.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building a small app and want to keep a button in the
I'm building a small app that takes things entered into an input field and
I'm building a small Validate object which basically exposes a validate method and takes
I am building a small applet in java. It works fine (really!) when I
I'm building this small java applet in which I need a JPanel which will
I am building a small rails app and I need a way to generate
I am building small app that will only display products in various categories. And
Im building a small MVC system and i want my controllers to be Singletons.
I'm building a small app to send my 2do list stuff to Evernote over
I'm building a small app that calculate hash from any given file to multiple

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.