Skip to content

Commit 1c88e55

Browse files
committed
add name to threadpools threads
1 parent 209b2c4 commit 1c88e55

12 files changed

+41
-15
lines changed

.classpath

+1-5
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@
4343
</attributes>
4444
</classpathentry>
4545
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
46-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
47-
<attributes>
48-
<attribute name="maven.pomderived" value="true"/>
49-
</attributes>
50-
</classpathentry>
5146
<classpathentry exported="true" kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
5247
<attributes>
5348
<attribute name="maven.pomderived" value="true"/>
@@ -65,5 +60,6 @@
6560
<attribute name="maven.pomderived" value="true"/>
6661
</attributes>
6762
</classpathentry>
63+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
6864
<classpathentry kind="output" path="target/classes"/>
6965
</classpath>

.settings/org.eclipse.jdt.core.prefs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annota
66
org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable
77
org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
88
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
9+
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
910
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
1011
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
1112
org.eclipse.jdt.core.compiler.compliance=1.7
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,31 @@
11
package codeine.executer;
22

33
import java.util.concurrent.BlockingQueue;
4+
import java.util.concurrent.ExecutorService;
5+
import java.util.concurrent.Executors;
46
import java.util.concurrent.LinkedBlockingQueue;
7+
import java.util.concurrent.ThreadFactory;
58
import java.util.concurrent.ThreadPoolExecutor;
69
import java.util.concurrent.TimeUnit;
710

11+
import com.google.common.util.concurrent.ThreadFactoryBuilder;
12+
813
public class ThreadPoolUtils {
914

1015
private static final int CAPACITY = 1000;
1116

12-
public static ThreadPoolExecutor newThreadPool(int maximumNumOfThreads){
17+
public static ThreadPoolExecutor newThreadPool(int maximumNumOfThreads, String poolName){
1318
BlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<>(CAPACITY);
14-
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(maximumNumOfThreads, maximumNumOfThreads, 1, TimeUnit.SECONDS , workQueue);
19+
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(maximumNumOfThreads, maximumNumOfThreads, 1, TimeUnit.SECONDS , workQueue, createFactory(poolName));
1520
threadPoolExecutor.allowCoreThreadTimeOut(true);
1621
return threadPoolExecutor;
1722
}
23+
//TODO I think it is better to use this version and eliminate the other one
24+
//need to check more about allowCoreThreadTimeOut and assert Error id above amount of tasks
25+
public static ExecutorService newFixedThreadPool(int concurrency, String poolName) {
26+
return Executors.newFixedThreadPool(concurrency,createFactory(poolName));
27+
}
28+
private static ThreadFactory createFactory(String poolName) {
29+
return new ThreadFactoryBuilder().setNameFormat(poolName+"-%d").build();
30+
}
1831
}

src/common/codeine/jsons/CommandExecutionStatusInfo.java

+4
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,8 @@ public String toString() {
130130
+ ", finished=" + finished + "]";
131131
}
132132

133+
public String command_name() {
134+
return command();
135+
}
136+
133137
}

src/common/codeine/jsons/peer_status/PeersProjectsStatusInWebServer.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import java.util.Map.Entry;
66
import java.util.concurrent.Callable;
77
import java.util.concurrent.ExecutorService;
8-
import java.util.concurrent.Executors;
98
import java.util.concurrent.FutureTask;
109
import java.util.concurrent.TimeUnit;
1110

@@ -15,6 +14,7 @@
1514

1615
import codeine.db.IStatusDatabaseConnector;
1716
import codeine.db.mysql.connectors.StatusDatabaseConnectorListProvider;
17+
import codeine.utils.ThreadUtils;
1818

1919
import com.google.common.base.Stopwatch;
2020
import com.google.common.collect.Lists;
@@ -66,7 +66,7 @@ private List<Map<String, PeerStatusJsonV2>> getUpdateMaps() {
6666
List<FutureTask<Map<String, PeerStatusJsonV2>>> futures = Lists.newArrayList();
6767
List<IStatusDatabaseConnector> providers = statusDatabaseConnectorListProvider.get();
6868
log.info("will get update concurrent with pool size " + providers.size());
69-
ExecutorService executor = Executors.newFixedThreadPool(providers.size());
69+
ExecutorService executor = ThreadUtils.newFixedThreadPool(providers.size(), "PeersProjectsStatus");
7070
for (final IStatusDatabaseConnector c : providers) {
7171
FutureTask<Map<String, PeerStatusJsonV2>> future = new FutureTask<Map<String, PeerStatusJsonV2>>(new Callable<Map<String,PeerStatusJsonV2>>() {
7272
@Override

src/common/codeine/utils/ThreadUtils.java

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package codeine.utils;
22

3+
import java.util.concurrent.ExecutorService;
4+
5+
import codeine.executer.ThreadPoolUtils;
6+
37

48

59
public class ThreadUtils {
@@ -29,4 +33,8 @@ public static Thread createThread(Runnable runnable) {
2933
public static Thread createThread(Runnable runnable, String threadName) {
3034
return new Thread(runnable, threadName);
3135
}
36+
37+
public static ExecutorService newFixedThreadPool(int concurrency, String poolName) {
38+
return ThreadPoolUtils.newFixedThreadPool(concurrency, poolName);
39+
}
3240
}

src/web_server/codeine/ConfigurationManagerServer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ private ThreadPoolExecutor getUpdateThreadPool(String key) {
7171
return dbUpdateThreadsMap.get(key, new Callable<ThreadPoolExecutor>() {
7272
@Override
7373
public ThreadPoolExecutor call() throws Exception {
74-
return ThreadPoolUtils.newThreadPool(NUM_OF_THREADS_FOR_EACH_DB);
74+
return ThreadPoolUtils.newThreadPool(NUM_OF_THREADS_FOR_EACH_DB, "ConfigurationManagerServer-DB-Update");
7575
}
7676
});
7777
} catch (ExecutionException e) {

src/web_server/codeine/ProjectConfigurationInPeerUpdater.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class ProjectConfigurationInPeerUpdater{
3535
@Inject private PeersProjectsStatus peersProjectsStatus;
3636
@Inject private NodeGetter nodeGetter;
3737
@Inject private Links links;
38-
private ThreadPoolExecutor threadPool = ThreadPoolUtils.newThreadPool(10);
38+
private ThreadPoolExecutor threadPool = ThreadPoolUtils.newThreadPool(10, "ProjectConfigurationInPeerUpdater");
3939

4040

4141
private void sendUpdateToPeers(Collection<PeerStatusJsonV2> allPeers) {

src/web_server/codeine/command_peer/AllNodesCommandExecuter.java

+4
Original file line numberDiff line numberDiff line change
@@ -296,4 +296,8 @@ public Object fileWriteSync() {
296296
public CommandExecutionStatusInfo commandExecutionInfo() {
297297
return commandExecutionInfo;
298298
}
299+
300+
public String commandString() {
301+
return commandExecutionInfo().project_name() + "/" + commandExecutionInfo().command_name() + "/" + commandExecutionInfo().id();
302+
}
299303
}

src/web_server/codeine/command_peer/CommandExecutionStrategy.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.util.List;
44
import java.util.concurrent.ExecutorService;
5-
import java.util.concurrent.Executors;
65

76
import org.apache.log4j.Logger;
87

@@ -11,6 +10,7 @@
1110
import codeine.configuration.Links;
1211
import codeine.jsons.project.ProjectJson;
1312
import codeine.permissions.IUserWithPermissions;
13+
import codeine.utils.ThreadUtils;
1414

1515
public abstract class CommandExecutionStrategy {
1616

@@ -58,7 +58,7 @@ protected void executeConcurrent(List<NodeWithPeerInfo> nodes, int concurrency)
5858
writeLine("concurrency is above limit, will reduce it to " + MAX_NODES_TO_EXECUTE);
5959
concurrency = MAX_NODES_TO_EXECUTE;
6060
}
61-
ExecutorService executor = Executors.newFixedThreadPool(concurrency);
61+
ExecutorService executor = ThreadUtils.newFixedThreadPool(concurrency, "CommandExecution-" + allNodesCommandExecuter.commandString());
6262
for (NodeWithPeerInfo peer : nodes) {
6363
commandNode(executor, peer, shouldOutputImmediatly);
6464
}

src/web_server/codeine/command_peer/PeerCommandWorker.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ private void execute() {
7676

7777
private void executeInternal() {
7878
String url = links.getPeerLink(node.peer_address()) + Constants.COMMAND_NODE_CONTEXT;
79-
log.info("commandNode " + command_info.project_name() + "/" + command_info.command_name() + "/" + executionInfo.id() + " for " + node.alias() + " url is " + url);
79+
log.info("commandNode " + allNodesCommandExecuter.commandString() + " for " + node.alias() + " url is " + url);
8080
try {
8181
ThreadUtils.sleep(getSleepTime());
8282
log.debug("running worker " + node);

src/web_server/codeine/plugins/DiscardOldCommandsPlugin.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class DiscardOldCommandsPlugin {
2424

2525
@Inject private PathHelper pathHelper;
2626
@Inject private Gson gson;
27-
private ThreadPoolExecutor executor = ThreadPoolUtils.newThreadPool(2);
27+
private ThreadPoolExecutor executor = ThreadPoolUtils.newThreadPool(2, "DiscardOldCommandsPlugin");
2828

2929
public void queueForDelete(final ProjectJson project) {
3030
if (!project.discard_old_commands().enabled()) {

0 commit comments

Comments
 (0)