diff --git a/spring-core/src/main/java/org/springframework/util/CustomizableThreadCreator.java b/spring-core/src/main/java/org/springframework/util/CustomizableThreadCreator.java index 0d1a368356..6a3e0dc087 100644 --- a/spring-core/src/main/java/org/springframework/util/CustomizableThreadCreator.java +++ b/spring-core/src/main/java/org/springframework/util/CustomizableThreadCreator.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ package org.springframework.util; import java.io.Serializable; +import java.util.concurrent.atomic.AtomicInteger; /** * Simple customizable helper class for creating threads. Provides various @@ -40,9 +41,7 @@ public class CustomizableThreadCreator implements Serializable { private ThreadGroup threadGroup; - private int threadCount = 0; - - private final Object threadCountMonitor = new SerializableMonitor(); + private final AtomicInteger threadCount = new AtomicInteger(); /** @@ -161,12 +160,7 @@ public class CustomizableThreadCreator implements Serializable { * @see #getThreadNamePrefix() */ protected String nextThreadName() { - int threadNumber = 0; - synchronized (this.threadCountMonitor) { - this.threadCount++; - threadNumber = this.threadCount; - } - return getThreadNamePrefix() + threadNumber; + return getThreadNamePrefix() + this.threadCount.incrementAndGet(); } /** @@ -177,11 +171,4 @@ public class CustomizableThreadCreator implements Serializable { return ClassUtils.getShortName(getClass()) + "-"; } - - /** - * Empty class used for a serializable monitor object. - */ - private static class SerializableMonitor implements Serializable { - } - }