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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T17:50:59+00:00 2026-05-21T17:50:59+00:00

It seems that all Guice’s out-of-the-box Scope implementations are inherently Thread-based (or ignore Threads

  • 0

It seems that all Guice’s out-of-the-box Scope implementations are inherently Thread-based (or ignore Threads entirely):

Scopes.SINGLETON and Scopes.NO_SCOPE ignore Threads and are the edge cases: global scope and no scope.

ServletScopes.REQUEST and ServletScopes.SESSION ultimately depend on retrieving scoped objects from a ThreadLocal<Context>. The retrieved Context holds a reference to the HttpServletRequest that holds a reference to the scoped objects stored as named attributes (where name is derived from com.google.inject.Key).

Class SimpleScope from the custom scope Guice wiki also provides a per-Thread implementation using a ThreadLocal<Map<Key<?>, Object>> member variable.

With that preamble, my question is this: how does one go about creating a non-Thread-based Scope? It seems that something that I can use to look up a Map<Key<?>, Object> is missing, as the only things passed in to Scope.scope() are a Key<T> and a Provider<T>.

Thanks in advance for your time.

  • 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-21T17:51:00+00:00Added an answer on May 21, 2026 at 5:51 pm

    It’s a bit unclear what you want – you don’t want scopes that are based on threads, and you don’t want scopes that ignore threads.

    But yes, scopes are intended to manage the lifecycle of an object and say when an instance should be reused. So really you’re asking “what are the other possibilities for re-using an instance beyond ‘always use the same instance’, ‘never use the same instance’, and ‘use an instance depending on the execution environment of the current thread’?”

    Here’s what comes to mind:

    • Use the same instance for a fixed amount of time. The example here would be of a configuration file that’s reloaded and reparsed every ten minutes.
    • Perform some network call to query whether a given object should be re-used (maybe it’s a fast call to determine whether we need to reconstruct the object, but the call for reconstructing the object is slow)
    • Re-use the same object until some outside call comes in telling us to reload
    • Re-use the same object per thread, but not with a scope that’s explicitly entered and left like the servlet scopes. (So one instance per thread)
    • A “this thread and child threads” scope that is based on an InheritableThreadLocal, not a plain ThreadLocal.
    • Related to that, a Scope and a threadpool-based ExecutorService that work togehter so that instances are shared between a thread and jobs it submits for background execution.
    • Pull instances out of a pool; this is tricky, since we’d need a good way to return objects to the pool when finished. (Maybe you could combine this idea with something like the request scope, so that objects can be returned to the pool when the request ends)
    • A scope that composes two or more other scopes, so for example we could get a configuration object that is re-read every 10 minutes except that the same instance is used through the lifetime of a given request.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a cross platform OpenGL project and it seems that all
The consensus seems to be that all foreign keys need to have indexes. How
In the Java Swing app I made it seems to me that all the
It seems that while I strive to maintain OO principles, it all seems so
That seems simple enough, but all Django Queries seems to be 'SELECT *' How
Seems to be a problem that many people have, but all the answers I
It seems to me that Guice implementation is doing some very tricky things when
It seems that all of the documentation I can find about OpenGL-ES says something
I can't seem to change width in IE7 http://jsfiddle.net/Mkb9n/1/ You can see that all
All source files seem to have compiled fine. However, since I achieved that, I

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.