I am declaring a Spring bean for a Java class that is used as a factory to create objects. I want to use this factory from different threads, the problem I am experienced is that threads are blocked when they try to create an object using the factory.
As far as I know spring beans are singletons by default, and this is what I want. I want the factory to be a singleton but I would like to create object using this factory from different threads. The method createObject() in the factory is not synchronized, therefore I do not understand very well why I'm having this synchronization issue.
Any suggestions about which is the best approach to achieve this?
This is the java code for the factory:
public class SomeFactory implements BeanFactoryAware {
private BeanFactory beanFactory;
public List<ConfigurableObjects> createObjects() {
List<ConfigurableObjects> objects = new ArrayList<ConfigurableObjects>();
objects.add((SomeObject)beanFactory.getBean(SomeObject.class.getName()));
return objects;
}
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
this.beanFactory = beanFactory;
}
}