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 6825571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:02:58+00:00 2026-05-26T22:02:58+00:00

Just finished a very long debug session. Please help me understand what root-cause/bad-practice caused

  • 0

Just finished a very long debug session. Please help me understand what root-cause/bad-practice caused this bug:

Beans A,B both had a property with an inner bean that looked exactly the same. Happily, I created bean C and reused it by doing <bean ref="C">.

However, bean C had a method called "setX" and a method called "getLongComputationBasedOnX". Turns out that upon first call to this method, it lazily cached with a member variable the computation. Further calls to setX do not reset the cache.

So, after I tried to make the world a better place and reuse, the 2 uses of C in A and B each set a different value to X, but now it was a single instance and the cache gave the value appropriate to A when called in B… 🙁

Is this a spring issue? Should I use parent instead of ref? Or is it a bad design of my “setX” and it should reset the cache?

  • 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-26T22:02:58+00:00Added an answer on May 26, 2026 at 10:02 pm

    Just use prototype scope:

    <bean id="C" scope="prototype"/>
    

    This way you have a single C declaration but two instances, one created when injecting to A and another one for B.

    In general it is hard to tell what the right design should be. Based on your explanation it seems like C was supposed to be used with only one x value. It should have been passed via constructor and made final to make this explicit though.

    Otherwise you will get nasty concurrent errors: one thread calls setX and getLongComputationBasedOnX subsequently but in the meantime other thread called setX. That being said I believe my prototype solution is the right one.

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

Sidebar

Related Questions

I've just finished a month long project of building a very complex map /
I just finished listening to a very eye-opening podcast on Hanselminutes about the definition
I just finished reading about scoping in the R intro , and am very
Just finished read this post by Greg Young, where he is talking about Microsoft
Just finished reading this blog post: http://www.skorks.com/2010/03/an-interview-question-that-prints-out-its-own-source-code-in-ruby/ In it, the author argues the case
I just finished writing my very first command-line tool in Objective-C, compiled it, and
I'm very new to Perl programming. I've just finished reading the Llama book. Up
I just finished my first web Part for Sharepoint WSS 3.0 and I'm very
I am very new to puppet and just trying to understand what the output
I just finished Scott Gu's Nerd Diner tutorial. I found it very helpful because

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.