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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:21:01+00:00 2026-05-17T16:21:01+00:00

I created a class that uses the the Java Executor API to create/manage a

  • 0

I created a class that uses the the Java Executor API to create/manage a pool with fixed number of threads.
Each thread needs a new instance of a particular object, and I would like to inject this object with Guice.
For the moment I’m using a Provider which provides new instances of the object through its get() method.

But now this class has a dependency to the Provider, which is Guice specific, effectively coupling the code to the Guice framework.
I would really like the class to be truly Guice agnostic, is this possible?

Just creating new instances of using the ‘new’ keyword is not an option, as this makes it impossible to replace those object by a mock implementation in the unit test.

Dependency injection is probably not suited for this and I would be better of creating a factory to get these objects?

  • 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-17T16:21:01+00:00Added an answer on May 17, 2026 at 4:21 pm

    One thing you may want to consider is building Guice from trunk and using that until Guice 3.0 is released. Then you can use JSR-330‘s javax.inject.Provider instead of Guice’s.

    Edit: Other than that, I’m generally of the opinion that coupling to the DI container (by importing something from com.google.inject, in this case) is less of an issue than people sometimes make it out to be. As long as you aren’t depending on the details of how you get your dependencies (e.g. injecting the Injector all over the place) it’s fairly easy to, say, change all places you injected Provider to take your own interface with a similar function instead. Depending on powerful features like scoping is where you really couple yourself to the container. I think that’s fine as well though, given how much ugliness and effort they save you.

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

Sidebar

Related Questions

I have a Java JDBC application that uses multiple threads to retrieve information from
I've created a Java class that connects to an IIS website requiring NTLM authentication.
im new to java. the standard code that is created after i created a
I have a project in Java I am running that uses an external JAR
I'm developping a small UML Class editor in Java, mainly a personal project, it
i'm working on a very simple server that uses ssl (in netbeans) - to
I successfully created an RMI service and client. I can call methods and so
I am having some trouble with implementing my own observer in Java on the
I have a problem with a specific java client library. Here is the situation:
I am a crazy Java beginner, FYI. I want to compile a program (actually

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.