abishkar bhattarai
abishkar bhattarai

Reputation: 7641

Thread scope vs request scope in spring

Can i replace request scope of spring with thread scope.As for non http request when operating in multithreading the access to bean service is not bound for the current thread. The thread scope allows every thread to access bean service.In the case if thread is accessing bean with request scope outside of http(say interceptor sometime call within http and sometime calling within serviceImpl to serviceImpl outside of http ).For http it is fine with request scope but when callfrom outside of http within multihreading environment the thread cannot get bean service because the request was not within http and there is error in creating the bean where the current thread tries to get bean service scope with request.If i scope thead instead of request does it create a problem if i have to operate in both http and non http outside of web request?

Upvotes: 0

Views: 3721

Answers (1)

muthu
muthu

Reputation: 5461

Yes sure You can replace the request scope of bean to thread scope

but you need to operate in both http and non http means it is better to add a custom scope for the bean

Refer this for the custom scopes

Upvotes: 1

Related Questions