1
I 더비 기본어떻게 DataNucleus + 더비에 대한 힙 사용을 줄일 수 있습니다
문제에 700K 서비스에서 50K의 일괄 항목을 저장합니다 다운로드 자바 데스크톱 응용 프로그램이 난 경우에만 작동한다는 것이다있다 -Xmx1024를 설정하면 응용 프로그램이 힙 오류 메시지와 충돌합니다. 데이터베이스의 최종 크기는 거의이
public static final void getItems() {
ItemsRequest req = new ItemsRequest();
Gson g = new Gson();
int next_index_to_read = 0;
int max_read_entry_count = 50000;
req.setLimit(max_read_entry_count);
ItemsResponse resp = null;
do{
resp = g.fromJson(postRequest(g.toJson(req)), ItemsResponse.class);
resp.saveItems();
next_index_to_read += max_read_entry_count;
req.setFrom(next_index_to_read);
}while(resp.getTotalItemsEntryCount()>next_index_to_read);
}
같은 약 1 억
다운로드를하기 위해 적은 메모리를
코드를 사용하려면 다음 코드를 최적화 할 수있는 방법을 제안 해주십시오 수있다하지만
및 데이터를 저장을 담당하는 코드는
public class ItemsResponse
public void saveItems() {
PersistenceManagerFactory pmf = PMF.getPmf();
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
if (data != null) {
for (Item item : data) {
Item item = null;
try {
item = pm.getObjectById(Item.class, item.getItemId());
} catch (Exception e) {
continue;
}
pm.makePersistent(item);
}
}
tx.commit();
} catch (Exception e) {
Logger.getLogger("com.example").error("ItemResponse.saveData", e);
} finally {
if (tx.isActive()) {
tx.rollback();
}
}
pm.close();
}