What is good way of implementing an object pool in Camel

935 views Asked by At

I have a few camel routes that call an external web service, i need to manage a session pool for this web service, keeping a few sessions open and reusing idle ones each time a camel route needs one.

Which is "safer" : - managing/persisting the session data in a db using JDBC for example or - implementing a static or singleton pool using apache-commons pool for example

2

There are 2 answers

0
dma_k On BEST ANSWER

Your session in WebService is represented by some SessionID, which you need to save/pool.So you basically need to pool WebService response (or part of it) which is returned by login operation. This response may leave in pool no longer then session timeout on WebService side.

If your WebService session is valid for days on server side and you want to recover your opened sessions after e.g. crash on client side, or you want to share opened sessions among several clients via DB, then I would use DB.

Otherwise if you have only one client, or it is OK that each client has it's own small cache, I would use in-memory pool. As subalternative you may think about sharing this pool among clients / multiple applications by means of Ehcache/Terracotta. And, by the way, these caches allow you to dump the pool contents contents to disk, which might be a good alternative to DB out-of-the-box.

1
Ben ODay On

if you are talking about JDBC connection pooling, then I'd recommend using DBCP or C3P0. If you are talking about POJO object pooling, then look at Spring object pooling