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

  • SEARCH
  • Home
  • 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 6355151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:42:23+00:00 2026-05-24T22:42:23+00:00

A (simplified) version of the problem I’m facing is as follows, in a Spring

  • 0

A (simplified) version of the problem I’m facing is as follows, in a Spring MVC application:

Two players can compete in a game. This game consist of starting from the same data (e.g. a certain chess position), playing the game seperately (but at the same time!) and comparing the results afterwards. To manage this I have:

  • An object that handles the game (e.g. checking if the players are ready, generating the start data, checking if the game is finished, …). Let’s call this the ‘GameHandler’ for easy referening.
  • For each player, an object that handles the game actions (e.g. moving a piece on the chess board). This is a session scoped bean, since it contains state information that is player-specific. Call this the ‘PlayerHandler’:

    <bean id=”playerHandler” class=”snip.PlayerHandler” scope=”session”>
    <aop:scoped-proxy />
    </bean>

The problem is that the GameHandler requires refences to both PlayerHandlers. However, since that’s a proxy’d session scoped bean, those references are pointing to the same bean, depending on which session I use to access it. E.g. two players, “Tom” and “Jerry”:

Session Tom: both playerHandler.getGameHandler().getPlayer1().getName() and playerHandler.getGameHandler().getPlayer2().getName() are Tom
Session Jerry: both are Jerry.

Now, as I understand it, this is the expected behavior. My question is not “why is this”, it’s “how do I solve this”. A solution that I found myself is to refer to the actual beans, not the proxies, when setting the references in the GameHandler:

public void setPlayerOne(PlayerHandler playerHandler) {
try {
        while (playerHandler instanceof Advised)
            playerHandler = (PlayerHandler ) ((Advised) playerHandler ).getTargetSource().getTarget();
    } catch (Exception e) {
        e.printStackTrace();
}
...

However, I am far from sure this is the best solution. So I’m looking for some answers: is my design wrong – if so, how would you design this? Did I miss a simple solution for this? Is this a Spring limitation?

  • 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-05-24T22:42:25+00:00Added an answer on May 24, 2026 at 10:42 pm

    Going back to your basic design, you’ll have to reconsider if your “PlayerHandler” really is session scoped, conceptually. Since you require access to it outside the scope of a given session (a thread handling a request for a specific session), it looks like it is not.

    One way to refactor this would be to move the “PlayerHandler” out to the application scope. Create a global singleton bean, call it “PlayerHandlerHolder” maybe, with a map that holds PlayerHandler instances keyed to session id, for instance. To prevent infinitely filling up this map, you could implement a session listener that removes PlayerHandler instances from the map on session destroy.

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

Sidebar

Related Questions

This is a simplified version of my problem. I have two buttons, and one
In this simplified version of my actual problem, I have two tables: User and
This is a simplified version of the original problem. I have a class called
This is the simplified version of the problem: We have a table on an
that's the problem.. This is a simplified version of what i would like do:
This is a simplified version of my database, with the actual problem applied to
This application is a much simplified version of what I am trying to accomplish,
Simplified version of the problem: So I have this query which is inside a
This is the simplified version of my problem: I'm trying to extract all letters
I'd really appreciate any help with this problem. This is a much simplified version

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.