简体   繁体   中英

Java resource pool

I have an app that stores data in XML. When user asks for data, XML is parsed into entities, which are then showed to him via something-like-servlet.

My problem is, that after every refresh, something-like-servlet has to process data again and parsing XML is expensive. There is also too much XML's to store all data in memory.

I was thinking about something like resource pooling, where program asks pool, if there is Entity with name foo in pool. If there is, foo is returned from pool, if not, foo is created from XML and saved to pool.

Something like this:

Entity entity = null;
entity.setId(id);
for(Entity entityFromPool : pool.getAllEntities()){
      if(entityFromPool.getId().equals(entity.getId())){
            entity = entityFromPool();
            isInPool = True;
}
if(!isInPool){
   entity = getEntityFromXML();
}

I have read about apache object pooling but if I understand it correctly, I can not store fe 5 different entities with it and then ask if entity with particular id exists in pool.

Is there any library that can help with my problem? Many thanks!

If you're referring to Commons Pool, then you can take a look at the KeyedObjectPool interface.

A "keyed" pooling interface.

A keyed pool maintains a pool of instances for each key value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM