java - Handle starvation in apache commons-pool -
i using 1.6 version of apache commons-pool library. per javadoc,
whenexhaustedaction specifies behavior of borrowobject() method when pool exhausted: can either when_exhausted_fail, when_exhausted_grow, or when_exhausted_block.
i want use borrowobject , if don't object within specified timeframe, need sort of handle handle scenario(like rescheduling tasks, if don't target object)
but option, here nosuchelementexception runtimeexception, need catch , handle error scenario. quite sceptical catching runtimeexception
is intended way of handling object starvation genericobjectpool or have other options ?
i've looked @ borrowobject
documentation , states throws these exceptions
illegalstateexception - after close has been called on pool. exception - when makeobject throws exception. nosuchelementexception - when pool exhausted , cannot or not return instance.
because nosuchelementexception
documented behavior of method, there nothing wrong catching around borrowobject
, handling liking.
i suggest catch right around call , wrap 1 of own, if other method in function throws nosuchelementexception
high level handler not confused pool exhaustion. wrapper exception can either checked or runtime, depending on preference , project requirements.
e.g
final t obj; try { obj = pool.borrowobject( ); } catch ( nosuchelementexception ex ) { throw new mypoolexhausetdexception( ex ); } // obj
Comments
Post a Comment