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

The Archive Base Latest Questions

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

I am currently refactoring the server side of an existing project. We are using

  • 0

I am currently refactoring the server side of an existing project.

We are using now guice to bind the specific modules and its objects.

Over the last 2 weeks we often have a problem which looks like that guice is mixing up some of the used object instances.

The problem is a class which is reponsible for building up a String which will be inserted in a database. This class is used from a rpc service which can be called quite fast in a row. So what happens is that RPC service 1 calls this class and in the meantime RPC service 2 is calling this class as well and changing the global parameter which are used for string building. The builder class is kind of stupid as it takes a param from a method sets some parts of the param as global variables and processes the string.

I think the main problem are the global variables but I dont know how I could get rid of them in an elegant way. They are used in all other methods which are called from the init method(e.g. startMethod() calls buildStringOne(), buildStringTwo() and those are accessing both global variables which are set in startMethod()).

Is there a better way how I could bind this object or do I need to remove the global variables and provide them as paramter in the other methods?

Thanks for your help.

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

    Using shared mutable state is asking for trouble. It sounds like your root problem is really a thread safety issue. However, you don’t have to solve thread safety issues by making mutable state thread safe — you can also just make it so the state is only visible to one thread.

    You may be able to use Guice’s request-scoped objects to solve this problem. If the troublesome class can be used in such a way that it’s injected, Guice will provide a new instance for each servlet request. If you’re using it in classes with longer scope than Request (such as Singleton), inject a Provider. Calling get() will return the appropriate Foo instance for the request that the calling thread is handling.

    See https://code.google.com/p/google-guice/wiki/ServletModule#Using_RequestScope for more.

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

Sidebar

Related Questions

I am currently refactoring an application that prints its status to the console window.
I'm currently refactoring/tidying up some old C code used in a C++ project, and
i'm currently refactoring a C-project, throwing about 1000 warnings at me. is there a
I am currently refactoring an existing codebase (EJBs) to rip out all blocks where
I'm currently refactoring some code on a project that is wrapping up, and I
I am currently refactoring my code for a web application developed using ASP.NET MVC3
I'm currently refactoring an existing DAL which has a facade the user calls and
I'm refactoring a project that involves passing around a lot of arrays. Currently, each
I'm currently refactoring code to replace Convert.To's to TryParse. I've come across the following
I'm currently reviewing/refactoring a multithreaded application which is supposed to be multithreaded in order

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.