-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0a8eeb8
commit 1f95673
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
...ests/appsec/springboot/src/main/java/datadog/smoketest/appsec/springboot/AsyncConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package datadog.smoketest.appsec.springboot; | ||
|
||
import java.util.concurrent.Executor; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.scheduling.annotation.EnableAsync; | ||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | ||
|
||
@Configuration | ||
@EnableAsync | ||
public class AsyncConfig { | ||
@Bean(name = "taskExecutor") | ||
public Executor taskExecutor() { | ||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); | ||
executor.setCorePoolSize(5); | ||
executor.setMaxPoolSize(10); | ||
executor.setQueueCapacity(100); | ||
executor.setThreadNamePrefix("Async-"); | ||
executor.initialize(); | ||
return executor; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...s/appsec/springboot/src/main/java/datadog/smoketest/appsec/springboot/MyAsyncService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package datadog.smoketest.appsec.springboot; | ||
|
||
import java.sql.Connection; | ||
import java.sql.DriverManager; | ||
import org.springframework.scheduling.annotation.Async; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class MyAsyncService { | ||
|
||
@Async("taskExecutor") | ||
public void performAsyncTask(String id) { | ||
try { | ||
Connection conn = DriverManager.getConnection("jdbc:h2:mem:testdb", "sa", ""); | ||
conn.createStatement().execute("SELECT 1 FROM DUAL WHERE '1' = '" + id + "'"); | ||
} catch (Exception e) { | ||
// ignore | ||
} | ||
} | ||
} |