开发者

add to list without bringing whole list into memory

I have a web service that holds information for users. Each user has a list of items, p开发者_运维问答ossibly thousands. I want to add an item to the list without loading the entire list. Is there a list implementation that allows you to add elements to the list without bringing the entire list into memory?


A Doubly Linked List. By definition it's not necessary to traverse the list to add something to the end since it contains a pointer to the end.


the list is on a remote database. – Lumpy

So the list is in a database, so it's not really a Java List? It's just a bunch of database rows? In that case why not just do an insert into the database to add another row?


INSERT INTO list VALUES 1, 2, 3;


Lazy proxies. You can use a JDK dynamic proxy (java.lang.reflect.Proxy) where you store only the information needed for retrieving the items from the database, not the items themselves. Only when calling the get(..), size(), contains(..) methods - fetch the data.

However I have a feeling that you are doing things the wrong way. Give more details about your implementation.


None that I know. With middlewares such as Terracotta, some collections (such as maps) can be loaded on-demand and partially, but this doesn't exist as-is in the standart JDK.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜