Skip to content

Commit

Permalink
test: verify that the analysis of the cause of issue 1702 is correct (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ggndnn authored and xingfudeshi committed Oct 21, 2019
1 parent b78f425 commit fcf6065
Showing 1 changed file with 7 additions and 2 deletions.
Expand Up @@ -15,6 +15,8 @@
*/
package io.seata.common.thread;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

Expand All @@ -24,9 +26,10 @@
* The type Named thread factory.
*
* @author jimin.jm @alibaba-inc.com
* @date 2018 /9/12
* @author ggndnn
*/
public class NamedThreadFactory implements ThreadFactory {
private final static Map<String, AtomicInteger> PREFIX_COUNTER = new ConcurrentHashMap<>();
private final AtomicInteger counter = new AtomicInteger(0);
private final String prefix;
private final int totalSize;
Expand All @@ -40,7 +43,9 @@ public class NamedThreadFactory implements ThreadFactory {
* @param makeDaemons the make daemons
*/
public NamedThreadFactory(String prefix, int totalSize, boolean makeDaemons) {
this.prefix = prefix;
PREFIX_COUNTER.putIfAbsent(prefix, new AtomicInteger(0));
int prefixCounter = PREFIX_COUNTER.get(prefix).incrementAndGet();
this.prefix = prefix + "_" + prefixCounter;
this.makeDaemons = makeDaemons;
this.totalSize = totalSize;
}
Expand Down

0 comments on commit fcf6065

Please sign in to comment.