show task title as a thread name for long-running tasks for easier-to-read threaddumps

GitOrigin-RevId: 4ad918f549c5c481b3d4236974a8f0d23a35cc2f
This commit is contained in:
Alexey Kudravtsev
2019-07-23 17:44:15 +03:00
committed by intellij-monorepo-bot
parent 09407cc913
commit 86e2b17055
3 changed files with 21 additions and 7 deletions
@@ -18,6 +18,7 @@ import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.ThrowableComputable;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.wm.ex.ProgressIndicatorEx;
import com.intellij.util.ConcurrencyUtil;
import com.intellij.util.ExceptionUtil;
import com.intellij.util.ObjectUtils;
import com.intellij.util.concurrency.AppExecutorUtil;
@@ -405,7 +406,7 @@ public class CoreProgressManager extends ProgressManager implements Disposable {
final long start = System.currentTimeMillis();
try {
runProcess(process, progressIndicator);
ConcurrencyUtil.runUnderThreadName(task.getTitle(), ()-> runProcess(process, progressIndicator));
}
catch (ProcessCanceledException e) {
processCanceled = true;
@@ -550,7 +550,7 @@ public class ApplicationImpl extends PlatformComponentManagerImpl implements App
final AtomicBoolean threadStarted = new AtomicBoolean();
//noinspection SSBasedInspection
SwingUtilities.invokeLater(() -> {
executeOnPooledThread(() -> {
executeOnPooledThread(ConcurrencyUtil.underThreadNameRunnable(progressTitle, () -> {
try {
ProgressManager.getInstance().runProcess(process, progress);
}
@@ -562,7 +562,7 @@ public class ApplicationImpl extends PlatformComponentManagerImpl implements App
progress.cancel();
throw e;
}
});
}));
threadStarted.set(true);
});
@@ -18,6 +18,7 @@ import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.ConcurrencyUtil;
import com.intellij.util.Consumer;
import gnu.trove.THashSet;
import org.jetbrains.annotations.NotNull;
@@ -114,16 +115,16 @@ public class CacheUpdateRunner {
try {
int threadsCount = indexingThreadCount();
if (threadsCount == 1 || application.isWriteAccessAllowed()) {
Runnable process = new MyRunnable(innerIndicator, suspendableIndicator, queue, isFinished, progressUpdater, project, fileProcessor);
Runnable process = createRunnable(project, queue, progressUpdater, suspendableIndicator, innerIndicator, isFinished, fileProcessor);
ProgressManager.getInstance().runProcess(process, innerIndicator);
}
else {
AtomicBoolean[] finishedRefs = new AtomicBoolean[threadsCount];
Future<?>[] futures = new Future<?>[threadsCount];
for (int i = 0; i < threadsCount; i++) {
AtomicBoolean ref = new AtomicBoolean();
finishedRefs[i] = ref;
Runnable process = new MyRunnable(innerIndicator, suspendableIndicator, queue, ref, progressUpdater, project, fileProcessor);
AtomicBoolean localFinished = new AtomicBoolean();
finishedRefs[i] = localFinished;
Runnable process = createRunnable(project, queue, progressUpdater, suspendableIndicator, innerIndicator, localFinished, fileProcessor);
futures[i] = application.executeOnPooledThread(process);
}
isFinished.set(waitForAll(finishedRefs, futures));
@@ -136,6 +137,18 @@ public class CacheUpdateRunner {
return isFinished.get();
}
@NotNull
private static Runnable createRunnable(@NotNull Project project,
@NotNull FileContentQueue queue,
@NotNull ProgressUpdater progressUpdater,
@NotNull ProgressIndicator suspendableIndicator,
@NotNull ProgressIndicatorBase innerIndicator,
@NotNull AtomicBoolean isFinished,
@NotNull Consumer<? super FileContent> fileProcessor) {
return ConcurrencyUtil.underThreadNameRunnable("Indexing",
new MyRunnable(innerIndicator, suspendableIndicator, queue, isFinished, progressUpdater, project, fileProcessor));
}
public static int indexingThreadCount() {
int threadsCount = Registry.intValue("caches.indexerThreadsCount");
if (threadsCount <= 0) {