0

我用 MongoDB 做了一个简单的程序。

每次连接 Web 请求时都会出现一个线程。
问题是即使断开连接,线程也不会消失。

随着时间的推移,'boundedElastic' 消失了。
但是“nioEventLoopGroup”和“reactor-http-nio”仍然存在。

我很担心,希望能解决这些问题。

@Slf4j
@CrossOrigin
@RestController
@RequiredArgsConstructor
public class UserController {
    private final UserEventRepository userEventRepository;

    @GetMapping(value = "/connect/{authToken}", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<UserEventResponseDto> connect(@PathVariable String authToken) {
        String userId = "test";
        return userEventRepository.findByAuthTokenAndGreaterThanCreatedAt(userId, authToken, LocalDateTime.now())
            .map(UserEventResponseDto::from)
            .takeUntil(dto -> dto.getEventType().isLogout())
            .subscribeOn(Schedulers.boundedElastic())
            .log();
    }
}


public interface UserEventRepository extends ReactiveMongoRepository<UserEvent, String> {
    @Tailable
    @Query("{ $and: [ { $or: [ { userId: ?0 }, { authToken: ?1 }] }, { createdAt: { $gt: ?2 } } ]}")
    Flux<UserEvent> findByAuthTokenAndGreaterThanCreatedAt(String userId, String authToken, LocalDateTime createdAt);
}

调试 > 线程:随着时间的推移,“有界弹性”被组织起来。

"Attach Listener"@4,152: RUNNING
"boundedElastic-1"@7,716 in group "main": WAIT
"boundedElastic-10"@8,374 in group "main": WAIT
"boundedElastic-11"@8,377 in group "main": WAIT
"boundedElastic-12"@8,379 in group "main": WAIT
...
"boundedElastic-9"@8,371 in group "main": WAIT
"boundedElastic-evictor-1"@6,796 in group "main": WAIT
"cluster-ClusterId{value='6152cebb4a320532e3a83ba5', description='null'}-localhost:27017"@5,624 in group "main": WAIT
"cluster-rtt-ClusterId{value='6152cebb4a320532e3a83ba5', description='null'}-localhost:27017"@5,625 in group "main": SLEEPING
"Common-Cleaner"@2,112 in group "InnocuousThreadGroup": WAIT
"DestroyJavaVM"@7,311 in group "main": RUNNING
"File Watcher"@7,163 in group "main": SLEEPING
"Finalizer"@7,331: WAIT
"Live Reload Server"@6,328 in group "main": RUNNING
"nioEventLoopGroup-3-1"@5,885 in group "main": RUNNING
"nioEventLoopGroup-3-10"@8,369 in group "main": RUNNING
"nioEventLoopGroup-3-11"@8,372 in group "main": RUNNING
"nioEventLoopGroup-3-12"@8,375 in group "main": RUNNING
"nioEventLoopGroup-3-13"@8,378 in group "main": RUNNING
"nioEventLoopGroup-3-14"@8,380 in group "main": RUNNING
"nioEventLoopGroup-3-15"@8,383 in group "main": RUNNING
"nioEventLoopGroup-3-16"@8,385 in group "main": RUNNING
"nioEventLoopGroup-3-17"@8,388 in group "main": RUNNING
"nioEventLoopGroup-3-18"@8,391 in group "main": RUNNING
"nioEventLoopGroup-3-19"@8,393 in group "main": RUNNING
"nioEventLoopGroup-3-2"@5,886 in group "main": RUNNING
"nioEventLoopGroup-3-20"@8,395 in group "main": RUNNING
"nioEventLoopGroup-3-21"@8,397 in group "main": RUNNING
"nioEventLoopGroup-3-22"@8,399 in group "main": RUNNING
"nioEventLoopGroup-3-23"@8,401 in group "main": RUNNING
"nioEventLoopGroup-3-24"@8,403 in group "main": RUNNING
"nioEventLoopGroup-3-3"@7,976 in group "main": RUNNING
"nioEventLoopGroup-3-4"@8,343 in group "main": RUNNING
"nioEventLoopGroup-3-5"@8,346 in group "main": RUNNING
"nioEventLoopGroup-3-6"@8,349 in group "main": RUNNING
"nioEventLoopGroup-3-7"@8,357 in group "main": RUNNING
"nioEventLoopGroup-3-8"@8,360 in group "main": RUNNING
"nioEventLoopGroup-3-9"@8,366 in group "main": RUNNING
"reactor-http-nio-1"@7,247 in group "main": RUNNING
"reactor-http-nio-10"@8,370 in group "main": RUNNING
"reactor-http-nio-11"@8,373 in group "main": RUNNING
"reactor-http-nio-12"@8,376 in group "main": RUNNING
"reactor-http-nio-2"@7,338 in group "main": RUNNING
"reactor-http-nio-3"@7,340 in group "main": RUNNING
"reactor-http-nio-4"@8,344 in group "main": RUNNING
"reactor-http-nio-5"@8,347 in group "main": RUNNING
"reactor-http-nio-6"@8,355 in group "main": RUNNING
"reactor-http-nio-7"@8,358 in group "main": RUNNING
"reactor-http-nio-8"@8,364 in group "main": RUNNING
"reactor-http-nio-9"@8,367 in group "main": RUNNING
"Reference Handler"@7,330: RUNNING
"RMI Scheduler(0)"@4,497: WAIT
"RMI TCP Accept-0"@1,687: RUNNING
"server"@7,269 in group "main": WAIT
"Signal Dispatcher"@7,332: RUNNING
4

0 回答 0