validate threadpool prefixes

This commit is contained in:
Ken Stevens 2021-11-07 17:15:38 -05:00
parent 238027d303
commit 882eb99f29
5 changed files with 6 additions and 3 deletions

View File

@ -404,7 +404,7 @@ public abstract class BaseConfig {
@Bean(name= BatchConstants.JOB_LAUNCHING_TASK_EXECUTOR) @Bean(name= BatchConstants.JOB_LAUNCHING_TASK_EXECUTOR)
public TaskExecutor jobLaunchingTaskExecutor() { public TaskExecutor jobLaunchingTaskExecutor() {
return ThreadPoolUtil.newThreadPool(0, 10, "JobLauncher-"); return ThreadPoolUtil.newThreadPool(0, 10, "job-launcher-");
} }
@Bean @Bean

View File

@ -1,6 +1,7 @@
package ca.uhn.fhir.util; package ca.uhn.fhir.util;
import ca.uhn.fhir.jpa.search.reindex.BlockPolicy; import ca.uhn.fhir.jpa.search.reindex.BlockPolicy;
import org.apache.commons.lang3.Validate;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -12,6 +13,8 @@ public final class ThreadPoolUtil {
@Nonnull @Nonnull
public static ThreadPoolTaskExecutor newThreadPool(int theCorePoolSize, int theMaxPoolSize, String theThreadNamePrefix) { public static ThreadPoolTaskExecutor newThreadPool(int theCorePoolSize, int theMaxPoolSize, String theThreadNamePrefix) {
Validate.matchesPattern(theThreadNamePrefix, "[a-z\\-]+", "Thread pool prefix name must consist only of lower-case letters and hyphens");
Validate.isTrue(theThreadNamePrefix.endsWith("-"), "Thread pool prefix name must end with a hyphen");
ThreadPoolTaskExecutor asyncTaskExecutor = new ThreadPoolTaskExecutor(); ThreadPoolTaskExecutor asyncTaskExecutor = new ThreadPoolTaskExecutor();
asyncTaskExecutor.setCorePoolSize(theCorePoolSize); asyncTaskExecutor.setCorePoolSize(theCorePoolSize);
asyncTaskExecutor.setMaxPoolSize(theMaxPoolSize); asyncTaskExecutor.setMaxPoolSize(theMaxPoolSize);

View File

@ -1503,7 +1503,7 @@ public class FhirInstanceValidatorR4Test extends BaseTest {
@Test @Test
public void testValidateBundleMultithreaded() throws IOException { public void testValidateBundleMultithreaded() throws IOException {
// setup // setup
StructureDefinition sd = loadStructureDefinition(myDefaultValidationSupport, "/r4/multithread/StructureDefinitionPatientV1.json"); StructureDefinition sd = loadStructureDefinition(myDefaultValidationSupport, "/r4/concurrent-bundle/StructureDefinitionPatientV1.json");
myStructureDefinitionMap.put("https://example.com/StructureDefinition/Patient-v1", sd); myStructureDefinitionMap.put("https://example.com/StructureDefinition/Patient-v1", sd);
@ -1539,7 +1539,7 @@ public class FhirInstanceValidatorR4Test extends BaseTest {
private Bundle buildBundle(int theSize, boolean theValidBundle) throws IOException { private Bundle buildBundle(int theSize, boolean theValidBundle) throws IOException {
BundleBuilder bundleBuilder = new BundleBuilder(ourCtx); BundleBuilder bundleBuilder = new BundleBuilder(ourCtx);
Patient p = ourCtx.newJsonParser().parseResource(Patient.class, loadResource("/r4/multithread/patient.json")); Patient p = ourCtx.newJsonParser().parseResource(Patient.class, loadResource("/r4/concurrent-bundle/patient.json"));
for (int i = 0; i < theSize; ++i) { for (int i = 0; i < theSize; ++i) {
bundleBuilder.addTransactionCreateEntry(p); bundleBuilder.addTransactionCreateEntry(p);
} }