{"id":23902680,"url":"https://github.com/mtumilowicz/spring-boot-async","last_synced_at":"2025-07-25T21:03:22.150Z","repository":{"id":110879351,"uuid":"142477148","full_name":"mtumilowicz/spring-boot-async","owner":"mtumilowicz","description":"Exploring basic features of Async in Spring.","archived":false,"fork":false,"pushed_at":"2024-11-22T21:11:13.000Z","size":98,"stargazers_count":10,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-11T00:13:14.047Z","etag":null,"topics":["async","completable-future","completablefuture","completablefuture-api","spring-async"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mtumilowicz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-07-26T18:10:04.000Z","updated_at":"2025-03-15T21:03:13.000Z","dependencies_parsed_at":"2025-04-11T00:23:26.622Z","dependency_job_id":null,"html_url":"https://github.com/mtumilowicz/spring-boot-async","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mtumilowicz/spring-boot-async","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtumilowicz%2Fspring-boot-async","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtumilowicz%2Fspring-boot-async/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtumilowicz%2Fspring-boot-async/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtumilowicz%2Fspring-boot-async/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mtumilowicz","download_url":"https://codeload.github.com/mtumilowicz/spring-boot-async/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtumilowicz%2Fspring-boot-async/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267061738,"owners_count":24029525,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-25T02:00:09.625Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async","completable-future","completablefuture","completablefuture-api","spring-async"],"created_at":"2025-01-04T22:49:48.713Z","updated_at":"2025-07-25T21:03:22.010Z","avatar_url":"https://github.com/mtumilowicz.png","language":"Java","readme":"[![Build Status](https://app.travis-ci.com/mtumilowicz/spring-boot-async.svg?branch=master)](https://app.travis-ci.com/mtumilowicz/spring-boot-async)\n\n# spring-boot-async\nThe main goal of this project is to explore basic features of `@Async` \nspring annotation and compare results with non-concurrent approach.\n\n* references\n    * https://spring.io/guides/gs/async-method/  \n    * http://www.baeldung.com/spring-async\n    * [Concurrency in Spring Boot Applications: Making the Right Choice by Andrei Shakirin](https://www.youtube.com/watch?v=vhHDlSV_0zg)\n\n# preface\nThis project shows how to create asynchronous queries using Spring.\n\nOur approach is to run expensive jobs in the background and wait \nfor the results using Java’s `CompletableFuture` interface.\n\n* spring boot concurrency options\n    * java executors and futures\n    * completable futures\n    * @Async annotation\n    * reactive programming\n    * virtual threads\n    * structured concurrency\n\n# manual\n1. Enable asynchronous support:\n    ```\n    @Configuration\n    @EnableAsync\n    class AsyncConfig {\n        @Bean\n        Executor asyncExecutor() {\n            ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();\n            executor.setCorePoolSize(4);\n            executor.setMaxPoolSize(4);\n            executor.setQueueCapacity(500);\n            executor.setThreadNamePrefix(\"EmailSender-\");\n            executor.initialize();\n            return executor;\n        }\n    }\n    ```\n    _Remark_: `asyncExecutor()` is used to customize default behaviour\n    and is not mandatory.\n1. Annotate method with `@Async`, and set return type to `CompletableFuture\u003cXXX\u003e`\n    where `XXX` is a wanted return type, for example:\n    ```\n    String customMethod() {\n    ...\n    }\n    ```\n    should be transformed to:\n    ```\n    CompletableFuture\u003cString\u003e customMethod() {\n    ...\n    }    \n    ```\n1. Consume it with `Completable API`, for example:\n    * `CompletableFuture.allOf(completableFutures.toArray(new CompletableFuture[]{})).join();`\n    * `CompletableFuture.allOf(completableFuture1, completableFuture2).join();`\n\n1. Extract requested return (note that `get()` throws checked exception):\n    * `XXX xxx = completableFuture.join()`\n\n# project description\n* `email-service` - microservice responsible for sending emails to given\n    users\n    * `EmailController` - REST controller; receives `login-message` map,\n    then asks `slow-user-service` for `emails` and sends messages\n    * in `EmailService` we have the same methods:\n        * `@Async` method - `asyncSend` - concurrently sends messages\n        * non-concurrent method - `send`\n    * in `AppRunner` we simulate interactions and compare times\n* `slow-user-service`\n    * `UserController` returns `User` bean (login, name, email...)\n    for given login\n    * in `UserRepository` we sleep thread for `user.repository.delay.seconds`\n    (configurable in `application.properties`) and then return requested user\n\n# tests\n**Coverage**: `93%`\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmtumilowicz%2Fspring-boot-async","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmtumilowicz%2Fspring-boot-async","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmtumilowicz%2Fspring-boot-async/lists"}