Skip to content

Commit

Permalink
修复parallelForEach的BUG
Browse files Browse the repository at this point in the history
  • Loading branch information
Em3rs0n authored and Em3rs0n committed Nov 24, 2018
1 parent 1b0c1a8 commit 7fcb0d7
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.gh0u1l5.wechatmagician.spellbook.util

import com.gh0u1l5.wechatmagician.spellbook.util.BasicUtil.tryVerbosely
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
import kotlin.concurrent.thread

/**
Expand Down Expand Up @@ -51,7 +53,11 @@ object ParallelUtil {
val iterator = iterator()
while (iterator.hasNext()) {
val item = iterator.next()
pool.execute { action(item) }
pool.execute {
tryVerbosely { action(item) } // 避免进程崩溃
}
}
pool.shutdown()
pool.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS)
}
}

0 comments on commit 7fcb0d7

Please sign in to comment.