11package io .sentrius .sso .sshproxy .config ;
22
33import java .util .concurrent .Executor ;
4+ import java .util .concurrent .ExecutorService ;
5+ import java .util .concurrent .ThreadPoolExecutor ;
46import io .sentrius .sso .core .services .TerminalService ;
57import jakarta .annotation .PreDestroy ;
8+ import lombok .RequiredArgsConstructor ;
69import lombok .extern .slf4j .Slf4j ;
710import org .springframework .beans .factory .annotation .Autowired ;
811import org .springframework .context .annotation .Bean ;
1316@ Slf4j
1417@ Configuration
1518@ EnableAsync
19+ @ RequiredArgsConstructor
1620public class TaskConfig {
1721
22+ private final TerminalService terminalService ;
23+
24+ // Keep a reference so we can shut it down explicitly on destroy, if desired.
1825 private ThreadPoolTaskExecutor executor ;
1926
2027 @ Bean (name = "taskExecutor" )
21- public Executor taskExecutor () {
22- ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor ();
23- executor .setCorePoolSize (15 );
24- executor .setMaxPoolSize (20 );
25- executor .setQueueCapacity (100 );
26- executor .setThreadNamePrefix ("SentriusTask-" );
27- executor .initialize ();
28- return executor ;
28+ public ThreadPoolTaskExecutor taskExecutor () {
29+ ThreadPoolTaskExecutor exec = new ThreadPoolTaskExecutor ();
30+ exec .setCorePoolSize (15 );
31+ exec .setMaxPoolSize (20 );
32+ exec .setQueueCapacity (100 );
33+ exec .setThreadNamePrefix ("ProxySession-" );
34+ exec .setWaitForTasksToCompleteOnShutdown (true );
35+ exec .setAwaitTerminationSeconds (30 );
36+ exec .initialize ();
37+
38+ this .executor = exec ; // assign the field, not a shadowed local
39+ return exec ; // expose as Executor for @Async
2940 }
3041
3142 @ PreDestroy
3243 public void shutdownExecutor () {
3344 if (executor != null ) {
45+ log .info ("Shutting down task executor" );
3446 executor .shutdown ();
3547 }
36- log . info ( "Shutting down executor" );
37- // Call shutdown on SshListenerService to close streams
48+ // If you truly want this on application shutdown:
49+ log . info ( "Shutting down TerminalService" );
3850 terminalService .shutdown ();
3951 }
40-
41- @ Autowired
42- private TerminalService terminalService ;
43- }
52+ }
0 commit comments