Skip to content

Commit 017218b

Browse files
committed
Выполнение операций на отдельном тред-пуле
1 parent 58aba46 commit 017218b

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

src/main/java/com/github/_1c_syntax/bsl/languageserver/AnalyzeProjectOnStart.java

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@
2828
import com.github._1c_syntax.bsl.languageserver.utils.Resources;
2929
import lombok.RequiredArgsConstructor;
3030
import org.springframework.context.event.EventListener;
31+
import org.springframework.scheduling.annotation.Async;
3132
import org.springframework.stereotype.Component;
3233

34+
import java.util.concurrent.ExecutionException;
35+
import java.util.concurrent.ForkJoinPool;
36+
3337
/**
3438
* Перехватчик события заполнения контекста сервера, запускающий анализ всех файлов контекста.
3539
*/
@@ -42,6 +46,7 @@ public class AnalyzeProjectOnStart {
4246
private final WorkDoneProgressHelper workDoneProgressHelper;
4347

4448
@EventListener
49+
@Async
4550
public void handleEvent(ServerContextPopulatedEvent event) {
4651
if (!configuration.getDiagnosticsOptions().isAnalyzeOnStart()) {
4752
return;
@@ -53,16 +58,28 @@ public void handleEvent(ServerContextPopulatedEvent event) {
5358
var progress = workDoneProgressHelper.createProgress(documentContexts.size(), getMessage("filesSuffix"));
5459
progress.beginProgress(getMessage("analyzeProject"));
5560

56-
documentContexts.forEach((DocumentContext documentContext) -> {
61+
var executorService = new ForkJoinPool(ForkJoinPool.getCommonPoolParallelism());
5762

58-
progress.tick();
63+
try {
64+
executorService.submit(() ->
65+
documentContexts.parallelStream().forEach((DocumentContext documentContext) -> {
66+
progress.tick();
5967

60-
serverContext.rebuildDocument(documentContext);
61-
diagnosticProvider.computeAndPublishDiagnostics(documentContext);
68+
serverContext.rebuildDocument(documentContext);
69+
diagnosticProvider.computeAndPublishDiagnostics(documentContext);
6270

63-
serverContext.tryClearDocument(documentContext);
71+
serverContext.tryClearDocument(documentContext);
72+
})
73+
).get();
6474

65-
});
75+
} catch (ExecutionException e) {
76+
throw new RuntimeException("Can't analyze project on start", e);
77+
} catch (InterruptedException e) {
78+
Thread.currentThread().interrupt();
79+
throw new RuntimeException("Interrupted while analyzing project on start", e);
80+
} finally {
81+
executorService.shutdown();
82+
}
6683

6784
progress.endProgress(getMessage("projectAnalyzed"));
6885
}

src/main/java/com/github/_1c_syntax/bsl/languageserver/context/ServerContext.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
import java.util.Set;
5151
import java.util.concurrent.ConcurrentHashMap;
5252
import java.util.concurrent.ExecutionException;
53-
import java.util.concurrent.Executors;
53+
import java.util.concurrent.ForkJoinPool;
5454
import java.util.concurrent.locks.ReadWriteLock;
5555
import java.util.concurrent.locks.ReentrantReadWriteLock;
5656

@@ -245,7 +245,7 @@ private Configuration computeConfigurationMetadata() {
245245
progress.beginProgress(getMessage("computeConfigurationMetadata"));
246246

247247
Configuration configuration;
248-
var executorService = Executors.newCachedThreadPool();
248+
var executorService = new ForkJoinPool(ForkJoinPool.getCommonPoolParallelism());
249249
try {
250250
configuration = executorService.submit(() -> Configuration.create(configurationRoot)).get();
251251
} catch (ExecutionException e) {

0 commit comments

Comments
 (0)