@@ -144,14 +144,6 @@ public SplitFactoryImpl(String apiToken, SplitClientConfig config) throws URISyn
144144 _syncManager = SyncManagerImp .build (config .streamingEnabled (), _splitSynchronizationTask , _splitFetcher , _segmentSynchronizationTaskImp , _splitCache , config .authServiceURL (), _httpclient , config .streamingServiceURL (), config .authRetryBackoffBase (), buildSSEdHttpClient (config ), _segmentCache );
145145 _syncManager .start ();
146146
147- // DestroyOnShutDown
148- if (config .destroyOnShutDown ()) {
149- Runtime .getRuntime ().addShutdownHook (new Thread (() -> {
150- // Using the full path to avoid conflicting with Thread.destroy()
151- SplitFactoryImpl .this .destroy ();
152- }));
153- }
154-
155147 // Evaluator
156148 _evaluator = new EvaluatorImp (_splitCache );
157149
@@ -160,6 +152,14 @@ public SplitFactoryImpl(String apiToken, SplitClientConfig config) throws URISyn
160152
161153 // SplitManager
162154 _manager = new SplitManagerImpl (_splitCache , config , _gates );
155+
156+ // DestroyOnShutDown
157+ if (config .destroyOnShutDown ()) {
158+ Runtime .getRuntime ().addShutdownHook (new Thread (() -> {
159+ // Using the full path to avoid conflicting with Thread.destroy()
160+ SplitFactoryImpl .this .destroy ();
161+ }));
162+ }
163163 }
164164
165165 @ Override
@@ -173,36 +173,31 @@ public SplitManager manager() {
173173 }
174174
175175 @ Override
176- public void destroy () {
177- synchronized (SplitFactoryImpl .class ) {
178- if (!isTerminated ) {
179- Runnable destroyer = () -> {
180- _log .info ("Shutdown called for split" );
181- try {
182- _segmentSynchronizationTaskImp .close ();
183- _log .info ("Successful shutdown of segment fetchers" );
184- _splitSynchronizationTask .close ();
185- _log .info ("Successful shutdown of splits" );
186- _impressionsManager .close ();
187- _log .info ("Successful shutdown of impressions manager" );
188- _unCachedFireAndForget .close ();
189- _log .info ("Successful shutdown of metrics 1" );
190- _cachedFireAndForgetMetrics .close ();
191- _log .info ("Successful shutdown of metrics 2" );
192- _httpclient .close ();
193- _log .info ("Successful shutdown of httpclient" );
194- _eventClient .close ();
195- _log .info ("Successful shutdown of eventClient" );
196- _syncManager .shutdown ();
197- _log .info ("Successful shutdown of syncManager" );
198- } catch (IOException e ) {
199- _log .error ("We could not shutdown split" , e );
200- }
201- };
202- destroyer .run ();
203- _apiKeyCounter .remove (_apiToken );
204- isTerminated = true ;
176+ public synchronized void destroy () {
177+ if (!isTerminated ) {
178+ _log .info ("Shutdown called for split" );
179+ try {
180+ _segmentSynchronizationTaskImp .close ();
181+ _log .info ("Successful shutdown of segment fetchers" );
182+ _splitSynchronizationTask .close ();
183+ _log .info ("Successful shutdown of splits" );
184+ _impressionsManager .close ();
185+ _log .info ("Successful shutdown of impressions manager" );
186+ _unCachedFireAndForget .close ();
187+ _log .info ("Successful shutdown of metrics 1" );
188+ _cachedFireAndForgetMetrics .close ();
189+ _log .info ("Successful shutdown of metrics 2" );
190+ _httpclient .close ();
191+ _log .info ("Successful shutdown of httpclient" );
192+ _eventClient .close ();
193+ _log .info ("Successful shutdown of eventClient" );
194+ _syncManager .shutdown ();
195+ _log .info ("Successful shutdown of syncManager" );
196+ } catch (IOException e ) {
197+ _log .error ("We could not shutdown split" , e );
205198 }
199+ _apiKeyCounter .remove (_apiToken );
200+ isTerminated = true ;
206201 }
207202 }
208203
0 commit comments