-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split async work into separate thread pools
- Loading branch information
Showing
6 changed files
with
153 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
common/src/main/scala/hexacraft/util/NamedThreadFactory.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package hexacraft.util | ||
|
||
import java.util.concurrent.ThreadFactory | ||
import java.util.concurrent.atomic.AtomicInteger | ||
|
||
class NamedThreadFactory(name: String) extends ThreadFactory { | ||
final private val group: ThreadGroup = Thread.currentThread.getThreadGroup | ||
final private val threadNumber = new AtomicInteger(1) | ||
final private val namePrefix: String = name + "-" | ||
|
||
override def newThread(r: Runnable) = { | ||
val t = new Thread(group, r, namePrefix + threadNumber.getAndIncrement, 0) | ||
if (t.isDaemon) t.setDaemon(false) | ||
if (t.getPriority != Thread.NORM_PRIORITY) t.setPriority(Thread.NORM_PRIORITY) | ||
t | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.