Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can a threadpool be reused after shutdown
    primarykey
    data
    text
    <p>I have a .csv file containing over 70 million lines of which each line is to generate a <strong>Runnable</strong> and then executed by threadpool. This Runnable will insert a record into Mysql.</p> <p>What's more , I want to record a position of the csv file for the <strong>RandomAccessFile</strong> to locate. The position is written to a <strong>File</strong>.I want to write this record when all the threads in threadpool are finished.So ThreadPoolExecutor.shutdown() is invoked. But when more lines come, I need a threadpool again. How can I reuse this current threadpool instead of make a new one.</p> <p>The code is as follows:</p> <pre><code>public static boolean processPage() throws Exception { long pos = getPosition(); long start = System.currentTimeMillis(); raf.seek(pos); if(pos==0) raf.readLine(); for (int i = 0; i &lt; PAGESIZE; i++) { String lineStr = raf.readLine(); if (lineStr == null) return false; String[] line = lineStr.split(","); final ExperienceLogDO log = CsvExperienceLog.generateLog(line); //System.out.println("userId: "+log.getUserId()%512); pool.execute(new Runnable(){ public void run(){ try { experienceService.insertExperienceLog(log); } catch (BaseException e) { e.printStackTrace(); } } }); long end = System.currentTimeMillis(); } BufferedWriter resultWriter = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(new File( RESULT_FILENAME), true))); resultWriter.write("\n"); resultWriter.write(String.valueOf(raf.getFilePointer())); resultWriter.close(); long time = System.currentTimeMillis()-start; System.out.println(time); return true; } </code></pre> <p>Thanks !</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload