Skip to content

Commit

Permalink
Fixing squid:S1118 #62
Browse files Browse the repository at this point in the history
Utility classes should not have public constructors
  • Loading branch information
smisger authored and oldratlee committed Mar 7, 2016
1 parent 4dbd656 commit 54e3a31
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 9 deletions.
8 changes: 6 additions & 2 deletions src/main/java/com/alibaba/ttl/threadpool/agent/TtlAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@
* @see <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/instrument/package-summary.html">The mechanism for instrumentation</a>
* @since 0.9.0
*/
public class TtlAgent {
public final class TtlAgent {
private static final Logger logger = Logger.getLogger(TtlAgent.class.getName());


private TtlAgent() {
throw new InstantiationError( "Must not instantiate this class" );
}

public static void premain(String agentArgs, Instrumentation inst) {
logger.info("[TtlAgent.premain] begin, agentArgs: " + agentArgs);
install(agentArgs, inst);
Expand Down
6 changes: 5 additions & 1 deletion src/test/java/com/alibaba/ttl/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@
/**
* @author Jerry Lee (oldratlee at gmail dot com)
*/
public class Utils {
public final class Utils {
public static final String PARENT_UNMODIFIED_IN_CHILD = "parent-created-unmodified-in-child";
public static final String PARENT_MODIFIED_IN_CHILD = "parent-created-modified-in-child";
public static final String PARENT_AFTER_CREATE_TTL_TASK = "parent-created-after-create-TtlTask";
public static final String CHILD = "child-created";

private Utils() {
throw new InstantiationError( "Must not instantiate this class" );
}

public static ConcurrentMap<String, TransmittableThreadLocal<String>> createTestTtlValue() {
ConcurrentMap<String, TransmittableThreadLocal<String>> ttlInstances = new ConcurrentHashMap<String, TransmittableThreadLocal<String>>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
*
* @author Jerry Lee (oldratlee at gmail dot com)
*/
public class DistributedTracerUseDemo {
public final class DistributedTracerUseDemo {

private DistributedTracerUseDemo() {
throw new InstantiationError( "Must not instantiate this class" );
}
static ThreadFactory threadFactory = new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
* @author Jerry Lee (oldratlee at gmail dot com)
*/
public class DistributedTracerUseDemo_WeakReferenceInsteadOfRefCounter {
public final class DistributedTracerUseDemo_WeakReferenceInsteadOfRefCounter {
static ThreadFactory threadFactory = new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
Expand All @@ -30,6 +30,10 @@ public Thread newThread(Runnable r) {

static ExecutorService executorService = TtlExecutors.getTtlExecutorService(Executors.newFixedThreadPool(1, threadFactory));

private DistributedTracerUseDemo_WeakReferenceInsteadOfRefCounter() {
throw new InstantiationError( "Must not instantiate this class" );
}

static {
// 挤满线程, 保证线程不是用的时候new的, 确保验证TTL的传递功能
Utils.expandThreadPool(executorService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
/**
* @author Jerry Lee (oldratlee at gmail dot com)
*/
public class NoMemoryLeak_ThreadLocal_NoRemove {
public final class NoMemoryLeak_ThreadLocal_NoRemove {

private NoMemoryLeak_ThreadLocal_NoRemove() {
throw new InstantiationError( "Must not instantiate this class" );
}

public static void main(String[] args) throws Exception {
long counter = 0;
while (true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
/**
* @author Jerry Lee (oldratlee at gmail dot com)
*/
public class CreateThreadLocalInstanceTps {
public final class CreateThreadLocalInstanceTps {

private CreateThreadLocalInstanceTps() {
throw new InstantiationError( "Must not instantiate this class" );
}

public static void main(String[] args) throws Exception {
TpsCounter tpsCounter = new TpsCounter(2);
tpsCounter.run(new Runnable() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@
/**
* @author Jerry Lee (oldratlee at gmail dot com)
*/
public class AgentCheck {
public final class AgentCheck {
static ExecutorService executorService = Executors.newFixedThreadPool(3);
static ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(3);

private AgentCheck() {
throw new InstantiationError( "Must not instantiate this class" );
}
static {
expandThreadPool(executorService);
expandThreadPool(scheduledExecutorService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
/**
* @author Jerry Lee (oldratlee at gmail dot com)
*/
public class AgentDemo {
public final class AgentDemo {

static TransmittableThreadLocal<String> stringTransmittableThreadLocal = new TransmittableThreadLocal<String>();

static TransmittableThreadLocal<Person> personReferenceTransmittableThreadLocal = new TransmittableThreadLocal<Person>() {
Expand All @@ -33,6 +34,10 @@ protected Person initialValue() {
return new Person("unnamed", -1);
}
};

private AgentDemo() {
throw new InstantiationError( "Must not instantiate this class" );
}

public static void main(String[] args) throws Exception {
ExecutorService executorService = Executors.newFixedThreadPool(3);
Expand Down

0 comments on commit 54e3a31

Please sign in to comment.