private void serialize(POS pos, DictionaryFileType fileType) throws JWNLException { ObjectDictionaryFile file = destinationFiles.getDictionaryFile(pos, fileType); int count = 0; for (Iterator<? extends DictionaryElement> itr = getIterator(pos, fileType); itr.hasNext(); itr.next()) { if (++count % 10000 == 0) { System.out.println("Counted and cached element " + count + "..."); } } Map<Object, DictionaryElement> map = new ConcurrentHashMap<>(); Iterator<? extends DictionaryElement> listItr = getIterator(pos, fileType); while (listItr.hasNext()) { DictionaryElement elt = listItr.next(); map.put(elt.getKey(), elt); } file.writeObject(map); file.close(); System.gc(); Runtime rt = Runtime.getRuntime(); System.out.println("total mem: " + rt.totalMemory() / 1024L + "K free mem: " + rt.freeMemory() / 1024L + "K"); System.out.println("Successfully serialized " + count + " elements..."); }
private void serialize(POS pos, DictionaryFileType fileType) throws JWNLException { ObjectDictionaryFile file = destinationFiles.getDictionaryFile(pos, fileType); int count = 0; for (Iterator<? extends DictionaryElement> itr = getIterator(pos, fileType); itr.hasNext(); itr.next()) { if (++count % 10000 == 0) { System.out.println("Counted and cached element " + count + "..."); } } Map<Object, DictionaryElement> map = new ConcurrentHashMap<>(); Iterator<? extends DictionaryElement> listItr = getIterator(pos, fileType); while (listItr.hasNext()) { DictionaryElement elt = listItr.next(); map.put(elt.getKey(), elt); } file.writeObject(map); file.close(); System.gc(); Runtime rt = Runtime.getRuntime(); System.out.println("total mem: " + rt.totalMemory() / 1024L + "K free mem: " + rt.freeMemory() / 1024L + "K"); System.out.println("Successfully serialized " + count + " elements..."); }
private DictionaryElement cache(DictionaryElementType fileType, DictionaryElement obj) { if (isCachingEnabled() && null != obj) { getCaches().cacheObject(fileType, obj.getPOS(), obj.getKey(), obj); } return obj; }
private DictionaryElement cache(DictionaryElementType fileType, DictionaryElement obj) { if (isCachingEnabled() && null != obj) { getCaches().cacheObject(fileType, obj.getPOS(), obj.getKey(), obj); } return obj; }