@@ -67,37 +67,37 @@ void cachedNamedOnlyLinearTokenSequenceMatcherIsSafeForConcurrentUse() throws Ex
6767
6868 int threads = 16 ;
6969 int iterations = 1_000 ;
70- ExecutorService executor = Executors .newFixedThreadPool (threads );
7170 CountDownLatch ready = new CountDownLatch (threads );
7271 CountDownLatch start = new CountDownLatch (1 );
7372 CountDownLatch done = new CountDownLatch (threads );
7473 ConcurrentLinkedQueue <Throwable > failures = new ConcurrentLinkedQueue <>();
7574
76- for (int thread = 0 ; thread < threads ; thread ++) {
77- executor .execute (
78- () -> {
79- ready .countDown ();
80- try {
81- start .await ();
82- for (int iteration = 0 ; iteration < iterations ; iteration ++) {
83- assertMatchWithOptionalCaptures (shared , groupNumbers );
84- assertMatchWithoutOptionalCaptures (shared , groupNumbers );
85- assertFailedMatchLeavesArraysUntouched (shared , groupCount );
86- assertTrue (shared .find ("noise " + WITH_OPTIONAL_CAPTURES ));
87- assertFalse (shared .find ("noise malformed access log" ));
75+ try (ExecutorService executor = Executors .newFixedThreadPool (threads )) {
76+ for (int thread = 0 ; thread < threads ; thread ++) {
77+ executor .execute (
78+ () -> {
79+ ready .countDown ();
80+ try {
81+ start .await ();
82+ for (int iteration = 0 ; iteration < iterations ; iteration ++) {
83+ assertMatchWithOptionalCaptures (shared , groupNumbers );
84+ assertMatchWithoutOptionalCaptures (shared , groupNumbers );
85+ assertFailedMatchLeavesArraysUntouched (shared , groupCount );
86+ assertTrue (shared .find ("noise " + WITH_OPTIONAL_CAPTURES ));
87+ assertFalse (shared .find ("noise malformed access log" ));
88+ }
89+ } catch (Throwable failure ) {
90+ failures .add (failure );
91+ } finally {
92+ done .countDown ();
8893 }
89- } catch (Throwable failure ) {
90- failures .add (failure );
91- } finally {
92- done .countDown ();
93- }
94- });
95- }
94+ });
95+ }
9696
97- assertTrue (ready .await (10 , TimeUnit .SECONDS ), "workers did not become ready" );
98- start .countDown ();
99- assertTrue (done .await (30 , TimeUnit .SECONDS ), "workers did not finish" );
100- executor . shutdownNow ();
97+ assertTrue (ready .await (10 , TimeUnit .SECONDS ), "workers did not become ready" );
98+ start .countDown ();
99+ assertTrue (done .await (30 , TimeUnit .SECONDS ), "workers did not finish" );
100+ }
101101 assertTrue (failures .isEmpty (), () -> "concurrent LTS failure: " + failures .peek ());
102102 }
103103
@@ -112,48 +112,48 @@ void cachedLinearTokenSequenceMatcherSafelyRollsBackNestedOptionalSequences() th
112112
113113 int threads = 16 ;
114114 int iterations = 1_000 ;
115- ExecutorService executor = Executors .newFixedThreadPool (threads );
116115 CountDownLatch ready = new CountDownLatch (threads );
117116 CountDownLatch start = new CountDownLatch (1 );
118117 CountDownLatch done = new CountDownLatch (threads );
119118 ConcurrentLinkedQueue <Throwable > failures = new ConcurrentLinkedQueue <>();
120119
121- for (int thread = 0 ; thread < threads ; thread ++) {
122- executor .execute (
123- () -> {
124- ready .countDown ();
125- try {
126- start .await ();
127- for (int iteration = 0 ; iteration < iterations ; iteration ++) {
128- assertTrue (shared .matches ("abc" ));
129- assertTrue (shared .matches ("ac" ));
130- assertTrue (shared .matches ("c" ));
131- assertFalse (shared .matches ("ab" ));
132- assertNotNull (shared .match ("abc" ));
133- assertNotNull (shared .match ("ac" ));
134- assertNotNull (shared .match ("c" ));
135- assertNull (shared .match ("ab" ));
136- assertTrue (shared .find ("noise abc" ));
137- assertFalse (shared .find ("noise ab" ));
138-
139- int [] starts = {17 };
140- int [] ends = {19 };
141- assertFalse (shared .matchInto ("ab" , starts , ends ));
142- assertEquals (17 , starts [0 ]);
143- assertEquals (19 , ends [0 ]);
120+ try (ExecutorService executor = Executors .newFixedThreadPool (threads )) {
121+ for (int thread = 0 ; thread < threads ; thread ++) {
122+ executor .execute (
123+ () -> {
124+ ready .countDown ();
125+ try {
126+ start .await ();
127+ for (int iteration = 0 ; iteration < iterations ; iteration ++) {
128+ assertTrue (shared .matches ("abc" ));
129+ assertTrue (shared .matches ("ac" ));
130+ assertTrue (shared .matches ("c" ));
131+ assertFalse (shared .matches ("ab" ));
132+ assertNotNull (shared .match ("abc" ));
133+ assertNotNull (shared .match ("ac" ));
134+ assertNotNull (shared .match ("c" ));
135+ assertNull (shared .match ("ab" ));
136+ assertTrue (shared .find ("noise abc" ));
137+ assertFalse (shared .find ("noise ab" ));
138+
139+ int [] starts = {17 };
140+ int [] ends = {19 };
141+ assertFalse (shared .matchInto ("ab" , starts , ends ));
142+ assertEquals (17 , starts [0 ]);
143+ assertEquals (19 , ends [0 ]);
144+ }
145+ } catch (Throwable failure ) {
146+ failures .add (failure );
147+ } finally {
148+ done .countDown ();
144149 }
145- } catch (Throwable failure ) {
146- failures .add (failure );
147- } finally {
148- done .countDown ();
149- }
150- });
151- }
150+ });
151+ }
152152
153- assertTrue (ready .await (10 , TimeUnit .SECONDS ), "workers did not become ready" );
154- start .countDown ();
155- assertTrue (done .await (30 , TimeUnit .SECONDS ), "workers did not finish" );
156- executor . shutdownNow ();
153+ assertTrue (ready .await (10 , TimeUnit .SECONDS ), "workers did not become ready" );
154+ start .countDown ();
155+ assertTrue (done .await (30 , TimeUnit .SECONDS ), "workers did not finish" );
156+ }
157157 assertTrue (
158158 failures .isEmpty (), () -> "concurrent nested-optional LTS failure: " + failures .peek ());
159159 }
0 commit comments