Java "Pool" of longs or Oracle sequence with reusable values

Posted by Anthony Accioly on Stack Overflow See other posts from Stack Overflow or by Anthony Accioly
Published on 2011-11-25T17:47:18Z Indexed on 2011/11/25 17:50 UTC
Read the original article Hit count: 215

Filed under:
|

Several months ago I implemented a solution to choose unique values from a range between 1 and 65535 (16 bits). This range is used to generate unique Route Targets suffixes, which for this customer massive network (it's a huge ISP) are a very disputed resource, so any free index needs to become immediately available to the end user.

To tackle this requirement I used a BitSet. Allocate on the RT index with set and deallocate a suffix with clear. The method nextClearBit() can find the next available index. I handle synchronization / concurrency issues manually.

This works pretty well for a small range... The entire index is small (around 10k), it is blazing fast and can be easy serialized into a Blob field.

The problem is, some new devices can handle RTs of 32 bits (range 1 / 4294967296). Which can't be managed with a BitSet (it would, by itself, consume around 600Mb, plus be limited to int range). Even with this massive range available, the client still wants to free available Route Targets for the end user, mainly because the lowest ones (up to 65535) - which are compatible with old routers - are being heavily disputed.

Before I tell the customer that this is impossible and he will have to conform with my reusable index for lower RTs (up to 65550) and use a database sequence for the other ones (which means that when the user frees a Route Target, it will not become available again). Would anyone shed some light?

Maybe some kind soul already implemented a high performance number pool for Java (6 if it matters), or I am missing a killer feature of Oracle database (11R2 if it matters)... Wishful thinking.

Thank you very much in advance.

© Stack Overflow or respective owner

Related posts about java

Related posts about Oracle