diff --git a/spring-session-core/src/main/java/org/springframework/session/ReactiveMapSessionRepository.java b/spring-session-core/src/main/java/org/springframework/session/ReactiveMapSessionRepository.java index 70fc9edf7..141349f9b 100644 --- a/spring-session-core/src/main/java/org/springframework/session/ReactiveMapSessionRepository.java +++ b/spring-session-core/src/main/java/org/springframework/session/ReactiveMapSessionRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2022 the original author or authors. + * Copyright 2014-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ import java.util.Map; import reactor.core.publisher.Mono; +import reactor.core.scheduler.Schedulers; import org.springframework.session.events.SessionDeletedEvent; import org.springframework.session.events.SessionExpiredEvent; @@ -37,6 +38,7 @@ *

* * @author Rob Winch + * @author Yanming Zhou * @since 2.0 */ public class ReactiveMapSessionRepository implements ReactiveSessionRepository { @@ -98,11 +100,17 @@ public Mono deleteById(String id) { @Override public Mono createSession() { - return Mono.defer(() -> { - MapSession result = new MapSession(this.sessionIdGenerator); - result.setMaxInactiveInterval(this.defaultMaxInactiveInterval); - return Mono.just(result); - }); + // @formatter:off + return Mono.fromSupplier(() -> this.sessionIdGenerator.generate()) + .subscribeOn(Schedulers.boundedElastic()) + .publishOn(Schedulers.parallel()) + .map((sessionId) -> { + MapSession result = new MapSession(sessionId); + result.setMaxInactiveInterval(this.defaultMaxInactiveInterval); + result.setSessionIdGenerator(this.sessionIdGenerator); + return result; + }); + // @formatter:on } /**