spring-projects / spring-framework

Spring Framework
https://spring.io/projects/spring-framework
Apache License 2.0
56.47k stars 38.09k forks source link

generic object pooling support in spring [SPR-1560] #6258

Closed spring-projects-issues closed 18 years ago

spring-projects-issues commented 18 years ago

Daniel C. Amadei opened SPR-1560 and commented

Hi!

I've built a little framework for working with any kind of objects as pooled objects (in my case: XML parsers, XML Schema Validators, Apache Betwixt Encoders, etc) and the second version of this framework I built upon Spring and I noticed a reduction of aprox. 70% of the lines of code due to the IoC capabilities as I do not need to deal with configurations manually.

So, trying to contribute with the open source world I'm interested in sending this framework to be incorporated into spring, allowing it's users to use object pooling through template method much of the same way it's done with the orm helpers.

I've renamed the package of it to org.springframework and I'm attaching a file containing it and the testcases. So, if this is approved to be incorporated into Spring, please provide me some instructions on what more I should do.

Thanks, Daniel


Affects: 1.2.6

Attachments:

spring-projects-issues commented 18 years ago

Daniel C. Amadei commented

files containing object pool proposal for implementation

spring-projects-issues commented 18 years ago

Juergen Hoeller commented

Interesting... this is essentially a template/callback helper for a Commons ObjectPool. Not a bad idea, but I'm not sure how this fits into Spring core. We'll consider this, but I would assume that we only include this in Spring core in conjunction with an object pool abstraction that decouples the template class from Commons Pool.

Juergen

spring-projects-issues commented 18 years ago

Daniel C. Amadei commented

Refactored, adding the abstraction layer between the template and the apache commons pool.

spring-projects-issues commented 18 years ago

Daniel C. Amadei commented

I've uploaded a new version. This new version supports keyed pooling and includes a big refactoring as suggested to remove de coupling between Apache Commons Pool and the Pooling Template class.

I've tried to decouple the layers as most as was possible. Even though the only parts that remains coupled a little bit is the PoolableFactory as I had to extend the Apache interface and the implementation classes that delegates requests to the 'real' classes provided by apache commons pool.

Open for suggestions.

Daniel

spring-projects-issues commented 18 years ago

Juergen Hoeller commented

After some consideration, we've decided that the template/callback doesn't provide enough value add here to justify inclusion in Spring core. Provided that you use an underlying pool API that doesn't throw checked exception, it boils down to a simply try-finally block. And with such a try-finally block, not even including a catch clause, the template/callback style isn't very compelling - since the straight try-finally block is easy enough to code directly:

Object resource = pool.borrowObject(); try { // operate on the resource } finally { pool.returnObject(resource); }

The only thing necessary for this is a nice adapter for pool access. We could provide this as part of Spring, but it's not really a core responsibility of the framework. It's easy enough to write in a custom fashion: Just implement a class that provides borrowObject and returnObject methods on top of an underlying ObjectPool, converting exceptions to some RuntimeException. Usage would then be as simple as shown above.

Juergen