Results 1 to 3 of 3

Thread: Question related to protype scoped beans

  1. #1

    Default Question related to protype scoped beans

    Hello ,

    I have a question regarding protype scope.

    Background:
    I am using spring 3.0.I am using spring webservice module to create webservices and spring jdbc for data access.
    The dao methods are Autowired to webservice.

    Spring webservice uses a helper class which has dao methods autowired to it. Earlier this class was assumed to be singleton so it was autowired to service everything worked fine.

    Due to design change now this class need to maintain the state . I.e. remember values between method call. So we need to create a new instance of helper class everytime service is called. To resolve this I changed application context.xml and added bean with prototype scope like this :

    Code:
    <bean id="abcHelper" class="com.abc.AbcHelper" scope="prototype">
        </bean>
    I am getting the bean from application context .

    My bean class look like this :

    Code:
    package com.abc;
    public class AbcHelper {
    @Autowired
    private AncDAO abcDAO;
    
    public void initialize(String xyz){
            //initialization stuff
        }
    public String getXXX(){
    // SOME MORE STUFF
    }
    
    }
    I am calling this from spring webserivce as below :


    Code:
    AbcHelper abcHelper = (AbcHelper) context.getBean("abcHelper");
    abcHelper.initialize(service.get1());
    
    //some more stuff
    abcHelper.getXXX();
    Question : Is this approach correct. In general creating prototype scoped beans is considered a bad idea . If this approach is not correct what else can be done in my case. I need to call the helper class which needs dataaccess objects injected by spring container. And this also needs to maintain the state between invocations.

    This webservice is gonna be a heavily hit webservice with millions of hit each day. Would prototype scope will make it slow ?

  2. #2
    Join Date
    Dec 2009
    Location
    India
    Posts
    108

    Default

    I don't see any issue with this approach if you're sure that you have to use prototype scoped bean. I don't think using prototype bean necessarily slows down but of course since it is created per invocation and then may-be garbage collected, so there's some overhead. Rest depends upon the helper, if its instantiation is time consuming and so on.

  3. #3
    Join Date
    Oct 2012
    Posts
    1

    Default

    I don't see any affair with this access if you're abiding that you accept to use ancestor scoped bean.

    http://www.revolutionrugs.com/

    I don't anticipate application ancestor bean necessarily slows down but of advance back it is created per abracadabra and again may-be debris collected, so there's some overhead. Rest depends aloft the helper, if its instantiation is time arresting and so on.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •