Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Inherited Thread Scope Example Project #7

Open
jyore opened this issue Apr 25, 2015 · 3 comments
Open

Add Inherited Thread Scope Example Project #7

jyore opened this issue Apr 25, 2015 · 3 comments
Assignees
Milestone

Comments

@jyore
Copy link
Owner

jyore commented Apr 25, 2015

No description provided.

@jyore jyore self-assigned this Apr 25, 2015
@jyore jyore added this to the Version 1.0 milestone Apr 25, 2015
@jvmlet
Copy link

jvmlet commented Aug 21, 2018

Hello
Thanks for putting things together.
I've a question about using the inherited thread scope, so far I'm using it like this :
Setup :

    @Bean
    public static  CustomScopeConfigurer threadScopeConfigurer(){
        CustomScopeConfigurer customScopeConfigurer = new CustomScopeConfigurer();
        customScopeConfigurer.addScope("thread",new InheritedThreadScope());
        return customScopeConfigurer;
    }

   @Bean
   @Scope(value = "thread",proxyMode = ScopedProxyMode.TARGET_CLASS)
       public MyBean myBean(){
      return new MyBean();
   }

and then in the worker thread :

          applicationContext.getBean(MyBean.class) // create scoped bean

            try {
           // do the job spanning multiple threads
            }finally {
                InheritedThreadScopeContextHolder.instance().getContext().executeDesctructionCallbacks();
                InheritedThreadScopeContextHolder.instance().resetContext();
            }

So my question is : should I manually invoke executeDesctructionCallbacks and resetContext ?
Something that I missed ?
Thanks

@jyore
Copy link
Owner Author

jyore commented Aug 21, 2018

@jvmlet man, it has been awhile since I have worked with Spring, so I am trying to remember how this all worked.

I believe that all of the destruction/cleanup methods are automatically called when the bean's scope goes away. In this case, this is when the (parent) thread is released.

It should be easy enough to test by launching a thread and use an autowired bean in the spawned thread. You can register a destruction callback as well to do some sort of logging action to get the idea of how it should work.

@jvmlet
Copy link

jvmlet commented Aug 21, 2018

Thanks, but if the main thread is a pooled thread, it never ends .... Anyway, thanks for answering 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants