2017-05-16 5 views
0

JSONファイルには、約100000件のレコードがあります。私はそれらをすべてmantle.product.Productエンティティに書き込もうとしています。JSONから100000件以上のレコードをAT_ENTITYに読み込む

手順が開始し、約35000件のレコードで、「AT_ENTITYへのスローヒット:create:mantle.product.Product」というメッセージが表示され、悪化し始めます。それから、 'java.lang.OutOfMemoryError:GCオーバーヘッドの上限を超えました'というエラーで間違いなく停止します。この現象は私のPC上にあります。

ヒントを歓迎します。

これはコードです:

void processJson2(String filePath) { 
    //def json = new JsonSlurper().parseText(new BufferedReader(new InputStreamReader(this.getFileIO().openStream(), "UTF-8"))) 

    //will initialize class manually 
    def docReadReference = this.executionContext.resource.getLocationReference(filePath) 

    if (docReadReference.isFile()) { 
     //inputstream 
     InputStream inputFile = docReadReference.openStream() 
     TransactionFacade trxFacade = this.executionContext.getTransaction() 

     this.executionContext.artifactExecution.disableTarpit() 
     this.executionContext.artifactExecution.disableEntityEca() 
     this.executionContext.artifactExecution.disableAuthz() 

     trxFacade.runRequireNew(50000, "Error loading entity JSON data", { 

      try { 
       logMachine.info("Opening file ${docReadReference.isFile()}") 

       JsonSlurper slurper = new JsonSlurper().setType(JsonParserType.CHARACTER_SOURCE) 
       def json = slurper.parse(new BufferedReader(new InputStreamReader(inputFile, "UTF-8"))) 

       //writer 
       Long counter = 1 

       json.each { 
        this.executionContext.service.sync().name("create", "mantle.product.Product").parameters([productId: it.sourceFileReference]).call() 

        //display thousands 
        if (counter % 1000 == 0) { 
         logMachine.info("JSON rows processed ${counter} > ${it.sourceFileReference}") 
        } 

        //move counter 
        counter += 1 
       } 

       //log 
       logMachine.info("File processed.") 

      } catch (Throwable t) { 
       trxFacade.rollback("Error while processing JSON", t); 

       //log as warning 
       logMachine.warn("Incorrectly handled JSON parsing ${t.message}.") 
      } finally { 
       if (trxFacade.isTransactionInPlace()) trxFacade.commit(); 

       inputFile.close() 

       this.executionContext.artifactExecution.enableTarpit() 
       this.executionContext.artifactExecution.enableEntityEca() 
       this.executionContext.artifactExecution.enableAuthz() 
      } 
     }) 
    } 
} 

答えて

0

は、これが正常に動作するようなので、誰でも同様の問題がある場合、それが役立つことがあります。

  1. 私は遅いヒット問題を解決するためにMoquiDevConf、最初のものを使用していた、以来型AT_ENTITYのために削除するためにされ、
  2. 次の事、BufferedReaderのは、データを読み込むための最も効果的な解決策ではない、I jsonのArrayListを初期化するためにInputStreamを使用しました。

これが結果です:

InputStream inputFile = docReadReference.openStream() 
     TransactionFacade trxFacade = this.executionContext.getTransaction() 


     JsonSlurper slurper = new JsonSlurper().setType(JsonParserType.INDEX_OVERLAY) 
     //ArrayList<Object> json = slurper.parse(new BufferedReader(new InputStreamReader(inputFile, "UTF-8"))) 
     ArrayList<Object> json = slurper.parse(inputFile) 
関連する問題