// API callback
related_results_labels_thumbs({"version":"1.0","encoding":"UTF-8","feed":{"xmlns":"http://www.w3.org/2005/Atom","xmlns$openSearch":"http://a9.com/-/spec/opensearchrss/1.0/","xmlns$blogger":"http://schemas.google.com/blogger/2008","xmlns$georss":"http://www.georss.org/georss","xmlns$gd":"http://schemas.google.com/g/2005","xmlns$thr":"http://purl.org/syndication/thread/1.0","id":{"$t":"tag:blogger.com,1999:blog-1902220484592789830"},"updated":{"$t":"2024-11-06T08:33:41.552+05:30"},"category":[{"term":"java"},{"term":"java interview"},{"term":"Microservice"},{"term":"design pattern"},{"term":"spring"},{"term":"building microservices"},{"term":"java8"},{"term":"java interview questions"},{"term":"java microservices"},{"term":"cleancodetips"},{"term":"youtube"},{"term":"drools"},{"term":"drools decision table"},{"term":"drools rule engine"},{"term":"drools rule engine tutorial"},{"term":"drools syntax"},{"term":"drools tutorial"},{"term":"drools workbench"},{"term":"rule engine java"},{"term":"java8 feature"},{"term":"java8feature"},{"term":"Spring data"},{"term":"code smell"},{"term":"java design pattern"},{"term":"spring boot"},{"term":"thread"},{"term":"Automated Microservices"},{"term":"DDD"},{"term":"design pattern in java"},{"term":"jpa"},{"term":"spring cloud tutorial"},{"term":"Devops"},{"term":"Domain driven design"},{"term":"GOF"},{"term":"Spring data jpa"},{"term":"design pattern java"},{"term":"design patterns in java"},{"term":"j2ee"},{"term":"java interview questions for experienced"},{"term":"java pattern"},{"term":"microservice tutorial"},{"term":"microservices tutorial"},{"term":"mvc"},{"term":"spring mvc"},{"term":"Big data"},{"term":"Inheritance forest"},{"term":"Microservices example"},{"term":"Repository"},{"term":"Restful API"},{"term":"Spring Repository"},{"term":"Spring tutorial"},{"term":"SpringAsync"},{"term":"Springdata overview"},{"term":"anti pattern"},{"term":"databse"},{"term":"design patterns in java with realtime examples"},{"term":"design principles in java"},{"term":"devops practices"},{"term":"interface"},{"term":"interview"},{"term":"interview question on spring scope"},{"term":"java 5"},{"term":"java 6"},{"term":"java 8 stream"},{"term":"java jdk 8"},{"term":"java refactor"},{"term":"jdk 1.8"},{"term":"jenkins.Microservice with jenkins"},{"term":"jxls"},{"term":"lambda"},{"term":"microservice framework java"},{"term":"microservices architecture"},{"term":"microservices discovery"},{"term":"microservices with spring boot example"},{"term":"microservices-devops together"},{"term":"optional"},{"term":"overloading"},{"term":"refactoring code"},{"term":"singleton"},{"term":"spring cloud services"},{"term":"spring context"},{"term":"@Query"},{"term":"@Transactional"},{"term":"AOP"},{"term":"Adapter pattern"},{"term":"Angular4"},{"term":"BMT"},{"term":"CI"},{"term":"CMT"},{"term":"CQRS"},{"term":"Callback"},{"term":"Config server"},{"term":"DI"},{"term":"Decorator"},{"term":"Decorator pattern"},{"term":"Dependency injection"},{"term":"Deployment"},{"term":"Design decision"},{"term":"Docker"},{"term":"Docker Architechture"},{"term":"Docker Registry"},{"term":"Docker image"},{"term":"DocumentDB"},{"term":"Ejb"},{"term":"Encapsulation.Domain driven design"},{"term":"Event Source"},{"term":"Event driven architecture"},{"term":"Fileupload"},{"term":"Fileupload using Mock"},{"term":"Fileupload using junit"},{"term":"Flyweight"},{"term":"Flyweight pattern"},{"term":"GOF Flyweight"},{"term":"GOF singleton"},{"term":"Hashmap"},{"term":"Hexagonal"},{"term":"Hexagonal architechture"},{"term":"Hollywood Principle"},{"term":"IOC"},{"term":"Inheritance"},{"term":"Interview question on Design pattern"},{"term":"JCS"},{"term":"JDBC"},{"term":"JDBC API"},{"term":"JDBC Connection"},{"term":"JDBC Drivers"},{"term":"Java principles"},{"term":"Junit"},{"term":"MongoDB"},{"term":"PropertyPlaceholderConfigurer"},{"term":"Scalable"},{"term":"Shotgun Surgery"},{"term":"Sprig Mock"},{"term":"Spring How to tutorials"},{"term":"Spring Mock Mvc"},{"term":"Spring application context"},{"term":"Spring cloud config server"},{"term":"Spring with example"},{"term":"StactOverfloError"},{"term":"Tell Don't Ask"},{"term":"Transaction"},{"term":"Transaction \u0026 Checked Exception"},{"term":"Transaction \u0026 Runtime Exception"},{"term":"Type erasure"},{"term":"abstractclass"},{"term":"access modifiers in java with example program"},{"term":"antipattern"},{"term":"archetype in maven"},{"term":"archetype maven  own archetype"},{"term":"bad code"},{"term":"behavioral pattern"},{"term":"benifits of getter setter"},{"term":"breach encapsulation"},{"term":"callback method"},{"term":"can we overload main method"},{"term":"cant resolve property."},{"term":"casting example"},{"term":"chef"},{"term":"closure"},{"term":"code smell examples"},{"term":"config server tutorial"},{"term":"continuous delivery"},{"term":"custom archetype"},{"term":"declarative transaction"},{"term":"decorator pattern java"},{"term":"define devops"},{"term":"design pattern in java with example"},{"term":"devops concepts"},{"term":"devops continuous integration"},{"term":"devops definition"},{"term":"devops for beginners.agile"},{"term":"downcasting"},{"term":"download spring framework jars for eclipse spring installation"},{"term":"enum"},{"term":"etends"},{"term":"eureka server"},{"term":"event sourcing"},{"term":"event-driven"},{"term":"event-driven architechture"},{"term":"explicit casting"},{"term":"extensible"},{"term":"extention"},{"term":"factory method pattern.difference factory method and simple factory"},{"term":"factory pattern"},{"term":"fail-fast"},{"term":"feign client tutorial"},{"term":"fileupload mock"},{"term":"fluent api"},{"term":"functional"},{"term":"functional program"},{"term":"functional programming"},{"term":"functional programming for beginners"},{"term":"functional programming in java"},{"term":"functional programming vs oop"},{"term":"generics in java interview questions"},{"term":"generics interview questions Type Inference"},{"term":"getter"},{"term":"getter\/setter"},{"term":"getterandsetter"},{"term":"gof pattern"},{"term":"how to achieve multiple inheritance in java"},{"term":"inheritence"},{"term":"interface and Enum"},{"term":"interview question on spring data"},{"term":"java 1.8"},{"term":"java 1.8 api"},{"term":"java access modifiers"},{"term":"java based configuration"},{"term":"java casting"},{"term":"java constructor"},{"term":"java core pattern"},{"term":"java design patterns tutorial"},{"term":"java encapsulation"},{"term":"java final constructor"},{"term":"java functional"},{"term":"java functional programming"},{"term":"java microservices."},{"term":"java platform independent"},{"term":"java regex"},{"term":"java regex special characters"},{"term":"java regex tester"},{"term":"java regular expression tester"},{"term":"javaonfly"},{"term":"jdk1.8"},{"term":"jenkins devops"},{"term":"jre 1.8"},{"term":"jvm platform independent"},{"term":"lambda expression"},{"term":"learn devops"},{"term":"load multiple property file"},{"term":"main method"},{"term":"map"},{"term":"maven"},{"term":"maven archetype quickstart"},{"term":"maven placeholder"},{"term":"microservices architecture tutorial"},{"term":"microservices communication"},{"term":"microservices framework"},{"term":"microservices framework java"},{"term":"microservices in java"},{"term":"microservices java"},{"term":"mongo unwind"},{"term":"multiple inheritance in java"},{"term":"multiple inheritance in java example"},{"term":"multiple inheritance in java using interface"},{"term":"netflix microservices"},{"term":"onion architectural"},{"term":"opcodes"},{"term":"open closed principle example"},{"term":"orthogonal architecture"},{"term":"overload main"},{"term":"overloading in java"},{"term":"overloading meaning"},{"term":"parallel inheritance"},{"term":"placeholder"},{"term":"platform independent in java"},{"term":"platform independent java"},{"term":"port"},{"term":"port and hub"},{"term":"pring cloud netflix"},{"term":"program to an interface"},{"term":"properties"},{"term":"properties resolving"},{"term":"property file in multiple spring context"},{"term":"protected java"},{"term":"protected keyword in java"},{"term":"puppet"},{"term":"query annotation"},{"term":"queryDsl"},{"term":"robomongo"},{"term":"runtime"},{"term":"runtime behavior"},{"term":"salience in drools"},{"term":"scaling"},{"term":"scopes"},{"term":"server"},{"term":"server pool"},{"term":"service registry"},{"term":"servlet"},{"term":"servlet 3"},{"term":"setter"},{"term":"shotgun"},{"term":"simple factory"},{"term":"skeletal implementation"},{"term":"skeletal interface"},{"term":"spring boot cloud"},{"term":"spring boot microservices"},{"term":"spring cloud config server. spring cloud services"},{"term":"spring cloud netflix"},{"term":"spring cloud service"},{"term":"spring daya jpa"},{"term":"spring eclipse tutorial"},{"term":"spring framework download"},{"term":"spring framework eclipse"},{"term":"spring framework in java"},{"term":"spring mvc example"},{"term":"spring mvc java based"},{"term":"spring scope"},{"term":"spring singleton"},{"term":"spring transaction"},{"term":"spring-cloud-starter-feign"},{"term":"spring4"},{"term":"stackOverFlow"},{"term":"strategy"},{"term":"strategy design pattern in java"},{"term":"strategy pattern"},{"term":"strategy pattern in java"},{"term":"stream api"},{"term":"structural pattern"},{"term":"toString()"},{"term":"type safe query"},{"term":"upcasting"},{"term":"what is devops"},{"term":"what is functional programming"},{"term":"what is microservices"},{"term":"workflow engine"}],"title":{"type":"text","$t":"Make \u0026amp; Know Java"},"subtitle":{"type":"html","$t":"Want to master in Java!! make yourself Observer and make this blog observable (A Javaonfly Production)\n"},"link":[{"rel":"http://schemas.google.com/g/2005#feed","type":"application/atom+xml","href":"https:\/\/javaonfly.blogspot.com\/feeds\/posts\/default"},{"rel":"self","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/1902220484592789830\/posts\/default\/-\/SpringAsync?alt=json-in-script\u0026max-results=8"},{"rel":"alternate","type":"text/html","href":"https:\/\/javaonfly.blogspot.com\/search\/label\/SpringAsync"},{"rel":"hub","href":"http://pubsubhubbub.appspot.com/"}],"author":[{"name":{"$t":"Shamik Mitra"},"uri":{"$t":"http:\/\/www.blogger.com\/profile\/02620539092954103493"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"32","height":"32","src":"\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEjO2_A4uqRhlGdVcT56_sL024d9he6fReKq6CmpVwX7qqUKgBabEnhONHd9y8oFkNxgq80hXHMuC0mPAGRbIVw97aE63F0pwKB7fEKo397jRnCXRsc_1S1Px7VJSxmIsts\/s113\/534152_10200300633532106_2101616363_n.jpg"}}],"generator":{"version":"7.00","uri":"http://www.blogger.com","$t":"Blogger"},"openSearch$totalResults":{"$t":"2"},"openSearch$startIndex":{"$t":"1"},"openSearch$itemsPerPage":{"$t":"8"},"entry":[{"id":{"$t":"tag:blogger.com,1999:blog-1902220484592789830.post-4865068112119011518"},"published":{"$t":"2019-05-04T20:37:00.000+05:30"},"updated":{"$t":"2019-05-04T20:38:04.960+05:30"},"category":[{"scheme":"http://www.blogger.com/atom/ns#","term":"java interview"},{"scheme":"http://www.blogger.com/atom/ns#","term":"spring"},{"scheme":"http://www.blogger.com/atom/ns#","term":"spring boot"},{"scheme":"http://www.blogger.com/atom/ns#","term":"SpringAsync"}],"title":{"type":"text","$t":"Effective Advice on Spring @Async : Final Part ."},"content":{"type":"html","$t":"\u003Cdiv dir=\"ltr\" style=\"text-align: left;\" trbidi=\"on\"\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ca href=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEjMVGOyPZmwduOnSqt0nEFNQu7jszJWeAT2alPxarkBEzEmjLJcza0-j3wU9nVIwp5jcp5dNr88vN5RaEIMLdeJmNK1oNARSfkWVvKKxQh5WPD0YhaHgEZCCu-fLnoESWxP-zoPn3RCWnM\/s1600\/AsyncusgaeInSpringBoot.jpg\" imageanchor=\"1\" style=\"clear: left; float: left; margin-bottom: 1em; margin-right: 1em;\"\u003E\u003Cimg border=\"0\" data-original-height=\"232\" data-original-width=\"350\" height=\"212\" src=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEjMVGOyPZmwduOnSqt0nEFNQu7jszJWeAT2alPxarkBEzEmjLJcza0-j3wU9nVIwp5jcp5dNr88vN5RaEIMLdeJmNK1oNARSfkWVvKKxQh5WPD0YhaHgEZCCu-fLnoESWxP-zoPn3RCWnM\/s320\/AsyncusgaeInSpringBoot.jpg\" width=\"320\" \/\u003E\u003C\/a\u003E\u003C\/div\u003E\n\u003Cbr \/\u003E\n\u003Cdiv style=\"background: white; margin-bottom: 11.25pt; margin-left: 0in; margin-right: 0in; margin-top: 3.75pt;\"\u003E\n\u003Cspan style=\"color: #222635; font-family: \u0026quot;cambria\u0026quot; , \u0026quot;serif\u0026quot;; font-size: 14.5pt;\"\u003EIn my previous articles, I discussed the Spring Async concept\nand How to use it effectively. If you want to revisit,\u0026nbsp; below are the\nlinks, Also for new visitors I recommend,\u0026nbsp; please go through previous\nparts after reading this one.\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv pid=\"2\" style=\"-webkit-text-stroke-width: 0px; background: white; box-sizing: border-box; font-variant-caps: normal; font-variant-ligatures: normal; margin-bottom: 11.25pt; margin-left: 0in; margin-right: 0in; margin-top: 3.75pt; orphans: 2; text-align: start; text-decoration-color: initial; text-decoration-style: initial; widows: 2; word-spacing: 0px;\"\u003E\n\u003Cspan style=\"color: #222635; font-family: \u0026quot;cambria\u0026quot; , \u0026quot;serif\u0026quot;; font-size: 14.5pt;\"\u003E\u003Cbr \/\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv pid=\"2\" style=\"-webkit-text-stroke-width: 0px; background: white; box-sizing: border-box; font-variant-caps: normal; font-variant-ligatures: normal; margin-bottom: 11.25pt; margin-left: 0in; margin-right: 0in; margin-top: 3.75pt; orphans: 2; text-align: start; text-decoration-color: initial; text-decoration-style: initial; widows: 2; word-spacing: 0px;\"\u003E\n\u003Cspan style=\"color: #222635; font-family: \u0026quot;cambria\u0026quot; , \u0026quot;serif\u0026quot;; font-size: 14.5pt;\"\u003E\u003Cbr \/\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv pid=\"2\" style=\"-webkit-text-stroke-width: 0px; background: white; box-sizing: border-box; font-variant-caps: normal; font-variant-ligatures: normal; margin-bottom: 11.25pt; margin-left: 0in; margin-right: 0in; margin-top: 3.75pt; orphans: 2; text-align: start; text-decoration-color: initial; text-decoration-style: initial; widows: 2; word-spacing: 0px;\"\u003E\n\u003Cspan style=\"color: #222635; font-family: \u0026quot;cambria\u0026quot; , \u0026quot;serif\u0026quot;; font-size: 14.5pt;\"\u003E\u003Cspan style=\"box-sizing: border-box; color: #29a8ff; cursor: pointer; text-decoration: none;\"\u003E\u003Ca href=\"https:\/\/javaonfly.blogspot.com\/2019\/03\/effective-advice-on-spring-async-part-1.html\" style=\"box-sizing: border-box; cursor: pointer;\"\u003EPart 1\u003C\/a\u003E\u003C\/span\u003E::\u0026nbsp; How Spring\nAsync work internally, and how to use wisely so it assigns a task to a new\nthread.\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv pid=\"3\" style=\"-webkit-text-stroke-width: 0px; background: white; box-sizing: border-box; font-variant-caps: normal; font-variant-ligatures: normal; margin-bottom: 11.25pt; margin-left: 0in; margin-right: 0in; margin-top: 3.75pt; orphans: 2; text-align: start; text-decoration-color: initial; text-decoration-style: initial; widows: 2; word-spacing: 0px;\"\u003E\n\u003Cspan style=\"color: #222635; font-family: \u0026quot;cambria\u0026quot; , \u0026quot;serif\u0026quot;; font-size: 14.5pt;\"\u003E\u003Ca href=\"https:\/\/javaonfly.blogspot.com\/2019\/03\/SpringAsyncExceptionHandler.html\" style=\"box-sizing: border-box; cursor: pointer;\"\u003E\u003Cspan style=\"color: #29a8ff; text-decoration: none;\"\u003EPart2\u003C\/span\u003E\u003C\/a\u003E::\u0026nbsp; How to\nhandles Exception, If something goes wrong while executing a task.\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv pid=\"4\" style=\"-webkit-text-stroke-width: 0px; background: white; box-sizing: border-box; font-variant-caps: normal; font-variant-ligatures: normal; margin-bottom: 11.25pt; margin-left: 0in; margin-right: 0in; margin-top: 3.75pt; orphans: 2; text-align: start; text-decoration-color: initial; text-decoration-style: initial; widows: 2; word-spacing: 0px;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv pid=\"5\" style=\"-webkit-text-stroke-width: 0px; background: white; box-sizing: border-box; font-variant-caps: normal; font-variant-ligatures: normal; margin-bottom: 11.25pt; margin-left: 0in; margin-right: 0in; margin-top: 3.75pt; orphans: 2; text-align: start; text-decoration-color: initial; text-decoration-style: initial; widows: 2; word-spacing: 0px;\"\u003E\n\u003Cspan style=\"color: #222635; font-family: \u0026quot;cambria\u0026quot; , \u0026quot;serif\u0026quot;; font-size: 14.5pt;\"\u003EIn this part, we will discuss How Spring Async work with the\nweb.\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv pid=\"6\" style=\"-webkit-text-stroke-width: 0px; background: white; box-sizing: border-box; font-variant-caps: normal; font-variant-ligatures: normal; margin-bottom: 11.25pt; margin-left: 0in; margin-right: 0in; margin-top: 3.75pt; orphans: 2; text-align: start; text-decoration-color: initial; text-decoration-style: initial; widows: 2; word-spacing: 0px;\"\u003E\n\u003Cspan style=\"color: #222635; font-family: \u0026quot;cambria\u0026quot; , \u0026quot;serif\u0026quot;; font-size: 14.5pt;\"\u003EI am very excited to share an experience with you about Spring\nAsync and HttpRequest, as an interesting incident happened in one of my\nprojects, and I believe by sharing it I can save some valuable time of yours in\nfuture.\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv pid=\"6\" style=\"-webkit-text-stroke-width: 0px; background: white; box-sizing: border-box; font-variant-caps: normal; font-variant-ligatures: normal; margin-bottom: 11.25pt; margin-left: 0in; margin-right: 0in; margin-top: 3.75pt; orphans: 2; text-align: start; text-decoration-color: initial; text-decoration-style: initial; widows: 2; word-spacing: 0px;\"\u003E\n\u003Cspan style=\"color: #222635; font-family: \u0026quot;cambria\u0026quot; , \u0026quot;serif\u0026quot;; font-size: 14.5pt;\"\u003ELet me try to depict the scenario in Crisp word,\u0026nbsp;\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv pid=\"6\" style=\"-webkit-text-stroke-width: 0px; background: white; box-sizing: border-box; font-variant-caps: normal; font-variant-ligatures: normal; margin-bottom: 11.25pt; margin-left: 0in; margin-right: 0in; margin-top: 3.75pt; orphans: 2; text-align: start; text-decoration-color: initial; text-decoration-style: initial; widows: 2; word-spacing: 0px;\"\u003E\n\u003Cstrong style=\"box-sizing: border-box;\"\u003E\u003Cspan style=\"color: #222635; font-family: \u0026quot;cambria\u0026quot; , \u0026quot;serif\u0026quot;; font-size: 14.5pt;\"\u003EObjective:\u003C\/span\u003E\u003C\/strong\u003E\u003Cspan style=\"color: #222635; font-family: \u0026quot;cambria\u0026quot; , \u0026quot;serif\u0026quot;; font-size: 14.5pt;\"\u003E\u0026nbsp;The\u0026nbsp; objective was to pass some information from UI\u0026nbsp; to a backend controller,\nwhich will do some work and eventually calls an async mail service for triggers\na mail.\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv pid=\"11\" style=\"-webkit-text-stroke-width: 0px; background: white; box-sizing: border-box; font-variant-caps: normal; font-variant-ligatures: normal; margin-bottom: 11.25pt; margin-left: 0in; margin-right: 0in; margin-top: 3.75pt; orphans: 2; text-align: start; text-decoration-color: initial; text-decoration-style: initial; widows: 2; word-spacing: 0px;\"\u003E\n\u003Cspan style=\"color: #222635; font-family: \u0026quot;cambria\u0026quot; , \u0026quot;serif\u0026quot;; font-size: 14.5pt;\"\u003EOne of my Juniors did the following code(Try to replicate the\ncode intention with below code snippet, not the actual code ), can you spot\nwhere the problem lies?\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv pid=\"17\" style=\"-webkit-text-stroke-width: 0px; background: white; box-sizing: border-box; font-variant-caps: normal; font-variant-ligatures: normal; margin-bottom: 11.25pt; margin-left: 0in; margin-right: 0in; margin-top: 3.75pt; orphans: 2; text-align: start; text-decoration-color: initial; text-decoration-style: initial; widows: 2; word-spacing: 0px;\"\u003E\n\u003Cstrong style=\"box-sizing: border-box;\"\u003E\u003Cspan style=\"color: #222635; font-family: \u0026quot;cambria\u0026quot; , \u0026quot;serif\u0026quot;; font-size: 14.5pt;\"\u003EThe Controller\u003C\/span\u003E\u003C\/strong\u003E\u003Cspan style=\"color: #222635; font-family: \u0026quot;cambria\u0026quot; , \u0026quot;serif\u0026quot;; font-size: 14.5pt;\"\u003E:: Which\ncollect information from UI as a form\u0026nbsp; HTTP Servelet request, do some\noperation and pass it to async Mail service.\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"color: blue;\"\u003E\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003Epackage com.example.demo;\u003C\/span\u003E\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u0026nbsp;\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"color: blue;\"\u003E\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003Eimport javax.servlet.http.HttpServletRequest;\u003C\/span\u003E\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u0026nbsp;\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003Eimport org.springframework.beans.factory.annotation.Autowired;\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003Eimport org.springframework.web.bind.annotation.PathVariable;\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003Eimport org.springframework.web.bind.annotation.RequestMapping;\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003Eimport org.springframework.web.bind.annotation.RequestMethod;\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003Eimport org.springframework.web.bind.annotation.RestController;\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003E@RestController\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003Epublic class GreetController {\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003E@Autowired\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003Eprivate AsyncMailTrigger greeter;\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003E@RequestMapping(value = \"\/greet\", method =\nRequestMethod.GET)\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003Epublic String greet(HttpServletRequest request) throws Exception\n{\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003EString name = request.getParameter(\"name\");\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003Egreeter.asyncGreet(request);\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003ESystem.out.println(Thread.currentThread() + \" Says Name is\n\" + name);\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003ESystem.out.println(Thread.currentThread().getName() + \"\nHashcode\" + request.hashCode());\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003Ereturn name;\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003E}\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white; margin-bottom: 11.25pt; margin-left: 0in; margin-right: 0in; margin-top: 3.75pt;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003E}\u003C\/span\u003E\u003Cspan style=\"color: #222635;\"\u003E\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white; margin-bottom: 11.25pt; margin-left: 0in; margin-right: 0in; margin-top: 3.75pt;\"\u003E\n\u003Cspan style=\"color: #222635; font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003EThe Async Mail Service, I marked it as\n@Component you can easily change it to @Service. Here I have one method called\nasyncGreet which takes the HttpRequest, fetch the information from there and\nsay, trigger the mail(this part is omitted for simplicity). Notice I put a\nThread.sleep() here for a purpose, I will discuss the same later.\u003C\/span\u003E\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003Epackage com.example.demo;\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cbr \/\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003Eimport java.util.Map;\u003C\/span\u003E\u003C\/span\u003E\u003Cspan style=\"color: blue; font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u0026nbsp;\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003Eimport javax.servlet.http.HttpServletRequest;\u003C\/span\u003E\u003C\/span\u003E\u003Cspan style=\"color: blue; font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u0026nbsp;\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003Eimport org.springframework.scheduling.annotation.Async;\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003Eimport org.springframework.stereotype.Component;\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003E@Component\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003Epublic class AsyncMailTrigger {\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003E@Async\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003Epublic void asyncGreet(HttpServletRequest request) throws\nException {\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003ESystem.out.println(\"Trigger mail in a New Thread ::\n\"\u0026nbsp; +\nThread.currentThread().getName());\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003ESystem.out.println(Thread.currentThread().getName() + \"\ngreets before sleep\" + request.getParameter(\"name\"));\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003EThread.sleep(1000);\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003ESystem.out.println(Thread.currentThread().getName() + \"\ngreets\" + request.getParameter(\"name\"));\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003ESystem.out.println(Thread.currentThread().getName() + \"\nHashcode\" + request.hashCode());\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"color: blue;\"\u003E\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E}\u003C\/span\u003E\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u0026nbsp;\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white; margin-bottom: 11.25pt; margin-left: 0in; margin-right: 0in; margin-top: 3.75pt;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003E}\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white; margin-bottom: 11.25pt; margin-left: 0in; margin-right: 0in; margin-top: 3.75pt;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003E\u003Cbr \/\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white; margin-bottom: 11.25pt; margin-left: 0in; margin-right: 0in; margin-top: 3.75pt;\"\u003E\n\u003Cspan style=\"color: #222635; font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003ENow the main class\u003C\/span\u003E\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003Epackage com.example.demo;\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003Eimport org.springframework.boot.SpringApplication;\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003Eimport\norg.springframework.boot.autoconfigure.SpringBootApplication;\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003Eimport org.springframework.scheduling.annotation.EnableAsync;\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003E@SpringBootApplication\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003E@EnableAsync\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003Epublic class SpringAsyncWebApplication {\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003Epublic static void main(String[] args) {\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003ESpringApplication.run(SpringAsyncWebApplication.class, args);\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003E}\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white; margin-bottom: 11.25pt; margin-left: 0in; margin-right: 0in; margin-top: 3.75pt;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003E\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white; margin-bottom: 11.25pt; margin-left: 0in; margin-right: 0in; margin-top: 3.75pt;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003E}\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white; margin-bottom: 11.25pt; margin-left: 0in; margin-right: 0in; margin-top: 3.75pt;\"\u003E\n\u003Cspan style=\"color: #222635; font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003EIf I run this program output will very similar\nto below\u003C\/span\u003E\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003EThread[http-nio-8080-exec-1,5,main] Says Name is Shamik\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003Ehttp-nio-8080-exec-1 Hashcode 821691136\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003ETrigger mail in a New Thread:: task-1\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003Etask-1 greets before sleep Shamik\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003Etask-1 greets null task\u003C\/span\u003E\u003C\/span\u003E\u003Cspan style=\"color: blue; font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E-1 Hashcode 821691136\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"color: blue; font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cbr \/\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white; margin-bottom: 11.25pt; margin-left: 0in; margin-right: 0in; margin-top: 3.75pt;\"\u003E\n\u003Cspan style=\"color: #222635; font-family: \u0026quot;cambria\u0026quot; , \u0026quot;serif\u0026quot;; font-size: 14.5pt;\"\u003EPay attention to the output, the request has the information\nstill before sleep but after that, it magically disappears? Strange\nisn't?\u0026nbsp; But It is the same request object hashcode proves the same.\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv pid=\"24\" style=\"background: white; box-sizing: border-box; margin: 3.75pt 0in 11.25pt;\"\u003E\n\u003Cspan style=\"color: #222635; font-family: \u0026quot;cambria\u0026quot; , \u0026quot;serif\u0026quot;; font-size: 14.5pt;\"\u003EWhat happened ? what is the reason behind the disappearance of\nthe information from Request? That was happening to my junior, the mail\nrecipients, recipients name disappear from the request and mail is not\ntriggered.\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv pid=\"29\" style=\"background: white; box-sizing: border-box; margin: 3.75pt 0in 11.25pt;\"\u003E\n\u003Cstrong style=\"box-sizing: border-box;\"\u003E\u003Cspan style=\"color: #222635; font-family: \u0026quot;cambria\u0026quot; , \u0026quot;serif\u0026quot;; font-size: 14.5pt;\"\u003ELet's put Sherlock hats to\ninvestigate the problem.\u003C\/span\u003E\u003C\/strong\u003E\u003Cspan style=\"color: #222635; font-family: \u0026quot;cambria\u0026quot; , \u0026quot;serif\u0026quot;; font-size: 14.5pt;\"\u003E\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv pid=\"30\" style=\"background: white; box-sizing: border-box; margin: 3.75pt 0in 11.25pt;\"\u003E\n\u003Cspan style=\"color: #222635; font-family: \u0026quot;cambria\u0026quot; , \u0026quot;serif\u0026quot;; font-size: 14.5pt;\"\u003EIt is a very common problem with the request, to understand the\nproblem have a look, how a request lifecycle works.\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv pid=\"28\" style=\"background: white; box-sizing: border-box; margin: 3.75pt 0in 11.25pt;\"\u003E\n\u003Cspan style=\"color: #222635; font-family: \u0026quot;cambria\u0026quot; , \u0026quot;serif\u0026quot;; font-size: 14.5pt;\"\u003EThe request is created by the servlet container right before the\ncall to servlet service method, In Spring then request passes through\ndispatcher servlet, in the Dispatcher servlet identifies the controller by\nrequest mapping and calls the desired method in the controller, and when the\nrequest has been served, servlet container either delete the request object or\nreset the state of the request object. (This totally depends on the container\nimplementation, actually it maintains a pool of request). However, I am not\ngoing to the deep dive how container maintains the request object.\u0026nbsp;\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv pid=\"35\" style=\"background: white; box-sizing: border-box; margin: 3.75pt 0in 11.25pt;\"\u003E\n\u003Cspan style=\"color: #222635; font-family: \u0026quot;cambria\u0026quot; , \u0026quot;serif\u0026quot;; font-size: 14.5pt;\"\u003EBut keep one thing in mind once the request has been served and\nresponse is committed, container reset its state or destroy the request\nobject.\u0026nbsp;\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv pid=\"36\" style=\"background: white; box-sizing: border-box; margin: 3.75pt 0in 11.25pt;\"\u003E\n\u003Cspan style=\"color: #222635; font-family: \u0026quot;cambria\u0026quot; , \u0026quot;serif\u0026quot;; font-size: 14.5pt;\"\u003ENow put Spring Async part into the consideration, What async\ndid,\u0026nbsp; it picks one thread from the thread pool and assigns the task to it,\nIn our case, we pass the request object to the async thread and in the\nasyncGreet method, we are trying to extract info directly from the request.\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv pid=\"37\" style=\"background: white; box-sizing: border-box; margin: 3.75pt 0in 11.25pt;\"\u003E\n\u003Cspan style=\"color: #222635; font-family: \u0026quot;cambria\u0026quot; , \u0026quot;serif\u0026quot;; font-size: 14.5pt;\"\u003EBut as this is async our main thread (Controller part)\u0026nbsp;\nwill be not waiting for this thread to complete, so it's print the statement\nand commits the response, and refresh the state of the request object.\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv pid=\"38\" style=\"background: white; box-sizing: border-box; margin: 3.75pt 0in 11.25pt;\"\u003E\n\u003Cspan style=\"color: #222635; font-family: \u0026quot;cambria\u0026quot; , \u0026quot;serif\u0026quot;; font-size: 14.5pt;\"\u003EIronically we pass the\u0026nbsp;\u003Cstrong style=\"box-sizing: border-box;\"\u003Erequest\u0026nbsp;\u003C\/strong\u003Eobject\ndirectly to the async thread, still, the point where the response is not committed\nin the main thread, request holds the data, I explicitly put a sleep a statement\u0026nbsp; so in main thread response can be committed and refresh the\nrequest state, so after sleep we experience there is no data in the request, it\nvanishes, a great experiment to prove the incident.\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv pid=\"43\" style=\"background: white; box-sizing: border-box; margin: 3.75pt 0in 11.25pt;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv pid=\"44\" style=\"background: white; box-sizing: border-box; margin: 3.75pt 0in 11.25pt;\"\u003E\n\u003Cstrong style=\"box-sizing: border-box;\"\u003E\u003Cspan style=\"color: #222635; font-family: \u0026quot;cambria\u0026quot; , \u0026quot;serif\u0026quot;; font-size: 14.5pt;\"\u003EWhat we will learn from this\nexperiment?\u003C\/span\u003E\u003C\/strong\u003E\u003Cspan style=\"color: #222635; font-family: \u0026quot;cambria\u0026quot; , \u0026quot;serif\u0026quot;; font-size: 14.5pt;\"\u003E\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv pid=\"46\" style=\"background: white; box-sizing: border-box; margin: 3.75pt 0in 11.25pt;\"\u003E\n\u003Cstrong style=\"box-sizing: border-box;\"\u003E\u003Cspan style=\"color: #222635; font-family: \u0026quot;cambria\u0026quot; , \u0026quot;serif\u0026quot;; font-size: 14.5pt;\"\u003ENever pass Request object or any\nobject related to Request\/Response(headers), directly while using async you\nnever know when your response will be committed and refresh the state If you do\nyou will face an intermittent error.\u003C\/span\u003E\u003C\/strong\u003E\u003Cspan style=\"color: #222635; font-family: \u0026quot;cambria\u0026quot; , \u0026quot;serif\u0026quot;; font-size: 14.5pt;\"\u003E\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv pid=\"48\" style=\"background: white; box-sizing: border-box; margin: 3.75pt 0in 11.25pt;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv pid=\"49\" style=\"background: white; box-sizing: border-box; margin: 3.75pt 0in 11.25pt;\"\u003E\n\u003Cstrong style=\"box-sizing: border-box;\"\u003E\u003Cspan style=\"color: #222635; font-family: \u0026quot;cambria\u0026quot; , \u0026quot;serif\u0026quot;; font-size: 14.5pt;\"\u003EWhat can be done?\u003C\/span\u003E\u003C\/strong\u003E\u003Cspan style=\"color: #222635; font-family: \u0026quot;cambria\u0026quot; , \u0026quot;serif\u0026quot;; font-size: 14.5pt;\"\u003E\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv pid=\"50\" style=\"background: white; box-sizing: border-box; margin: 3.75pt 0in 11.25pt;\"\u003E\n\u003Cspan style=\"color: #222635; font-family: \u0026quot;cambria\u0026quot; , \u0026quot;serif\u0026quot;; font-size: 14.5pt;\"\u003EIf you need to pass a bunch of information from request create a\nvalue object and set the information and pass the value object to Spring Async,\nin this manner, you can create a concrete solution.\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003C\/div\u003E\n\u003Cdiv pid=\"59\" style=\"background: white; box-sizing: border-box; margin: 3.75pt 0in 11.25pt;\"\u003E\n\u003Cspan style=\"color: #222635; font-family: \u0026quot;cambria\u0026quot; , \u0026quot;serif\u0026quot;; font-size: 14.5pt;\"\u003E\u003Cb\u003ERequestVO Object\u003C\/b\u003E\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white; margin-bottom: 11.25pt; margin-left: 0in; margin-right: 0in; margin-top: 3.75pt;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003E\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white; margin-bottom: 11.25pt; margin-left: 0in; margin-right: 0in; margin-top: 3.75pt;\"\u003E\n\u003Cspan style=\"color: blue;\"\u003E\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u0026nbsp;\u003C\/span\u003E\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003Epackage com.example.demo;\u003C\/span\u003E\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u0026nbsp;\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003Epublic class RequestVO {\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003EString name;\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003Epublic String getName() {\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003Ereturn name;\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003E}\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003Epublic void setName(String name) {\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003Ethis.name = name;\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"color: blue;\"\u003E\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E}\u003C\/span\u003E\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u0026nbsp;\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white; margin-bottom: 11.25pt; margin-left: 0in; margin-right: 0in; margin-top: 3.75pt;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003E}\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white; margin-bottom: 11.25pt; margin-left: 0in; margin-right: 0in; margin-top: 3.75pt;\"\u003E\n\u003Cspan style=\"color: #222635; font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cb\u003EAsync Mail service\u003C\/b\u003E\u003C\/span\u003E\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white; margin-bottom: 11.25pt; margin-left: 0in; margin-right: 0in; margin-top: 3.75pt;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003E\u0026nbsp;\u003C\/span\u003E\u003C\/span\u003E\u003Cspan style=\"color: #222635; font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003Epackage com.example.demo;\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"color: #222635; font-family: \u0026quot;cambria\u0026quot; , \u0026quot;serif\u0026quot;; font-size: 14.5pt;\"\u003Eimport java.util.Map;\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"color: #222635; font-family: \u0026quot;cambria\u0026quot; , \u0026quot;serif\u0026quot;; font-size: 14.5pt;\"\u003Eimport javax.servlet.http.HttpServletRequest;\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"color: #222635; font-family: \u0026quot;cambria\u0026quot; , \u0026quot;serif\u0026quot;; font-size: 14.5pt;\"\u003Eimport org.springframework.scheduling.annotation.Async;\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"color: #222635; font-family: \u0026quot;cambria\u0026quot; , \u0026quot;serif\u0026quot;; font-size: 14.5pt;\"\u003Eimport org.springframework.stereotype.Component;\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003E@Component\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003Epublic class AsyncMailTrigger {\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003E@Async\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003Epublic void asyncGreet(RequestVO reqVO) throws Exception {\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003ESystem.out.println(\"Trigger mail in a New Thread ::\n\"\u0026nbsp; +\nThread.currentThread().getName());\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003ESystem.out.println(Thread.currentThread().getName() + \"\ngreets before sleep\" + reqVO.getName());\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003EThread.sleep(1000);\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003ESystem.out.println(Thread.currentThread().getName() + \"\ngreets\" + reqVO.getName());\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"color: blue;\"\u003E\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E}\u003C\/span\u003E\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u0026nbsp;\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white; margin-bottom: 11.25pt; margin-left: 0in; margin-right: 0in; margin-top: 3.75pt;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003E}\u003C\/span\u003E\u003Cspan style=\"color: #222635;\"\u003E\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white; margin-bottom: 11.25pt; margin-left: 0in; margin-right: 0in; margin-top: 3.75pt;\"\u003E\n\u003Cspan style=\"color: #222635; font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cb\u003EGreet Controller\u003C\/b\u003E\u003C\/span\u003E\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003Epackage com.example.demo;\u003C\/span\u003E\u003C\/span\u003E\u003Cspan style=\"color: blue; font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u0026nbsp;\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003Eimport javax.servlet.http.HttpServletRequest;\u003C\/span\u003E\u003C\/span\u003E\u003Cspan style=\"color: blue; font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u0026nbsp;\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003Eimport org.springframework.beans.factory.annotation.Autowired;\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003Eimport org.springframework.web.bind.annotation.PathVariable;\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003Eimport org.springframework.web.bind.annotation.RequestMapping;\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003Eimport org.springframework.web.bind.annotation.RequestMethod;\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003Eimport org.springframework.web.bind.annotation.RestController;\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003E@RestController\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003Epublic class GreetController {\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003E@Autowired\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003Eprivate AsyncMailTrigger greeter;\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003E@RequestMapping(value = \"\/greet\", method =\nRequestMethod.GET)\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003Epublic String greet(HttpServletRequest request) throws Exception\n{\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003EString name = request.getParameter(\"name\");\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003ERequestVO vo = new RequestVO();\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003Evo.setName(name);\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003E\/\/greeter.asyncGreet(request);\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003Egreeter.asyncGreet(vo);\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003ESystem.out.println(Thread.currentThread() + \" Says Name is\n\" + name);\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003ESystem.out.println(Thread.currentThread().getName() + \"\nHashcode\" + request.hashCode());\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003Ereturn name;\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003E}\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white; margin-bottom: 11.25pt; margin-left: 0in; margin-right: 0in; margin-top: 3.75pt;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003E\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white; margin-bottom: 11.25pt; margin-left: 0in; margin-right: 0in; margin-top: 3.75pt;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003E}\u003C\/span\u003E\u003Cspan style=\"color: #222635;\"\u003E\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white; margin-bottom: 11.25pt; margin-left: 0in; margin-right: 0in; margin-top: 3.75pt;\"\u003E\n\u003Cspan style=\"color: #222635; font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cb\u003EOutput\u003C\/b\u003E\u003C\/span\u003E\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003EThread[http-nio-8080-exec-1,5,main] Says Name is Shamik\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003Ehttp-nio-8080-exec-1 Hashcode 1669579896\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003ETrigger mail in a New Thread:: task-1\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003Etask-1 greets before sleep Shamik\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white; margin-bottom: 11.25pt; margin-left: 0in; margin-right: 0in; margin-top: 3.75pt;\"\u003E\n\u003Cspan style=\"font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E\u003Cspan style=\"color: blue;\"\u003Etask-1 greets Shamik\u003C\/span\u003E\u003Cspan style=\"color: #222635;\"\u003E\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white; margin-bottom: 11.25pt; margin-left: 0in; margin-right: 0in; margin-top: 3.75pt;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white; margin-bottom: 11.25pt; margin-left: 0in; margin-right: 0in; margin-top: 3.75pt;\"\u003E\n\u003Cstrong\u003E\u003Cspan style=\"color: #222635; font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003EConclusion\u003C\/span\u003E\u003C\/strong\u003E\u003Cspan style=\"color: #222635; font-family: \u0026quot;cambria\u0026quot; , serif; font-size: 14.5pt;\"\u003E: Hope you enjoyed the article If you have questions, please\nput your questions on the comment box.\u003C\/span\u003E\u003Cspan style=\"color: #222635; font-family: \u0026quot;cambria\u0026quot; , \u0026quot;serif\u0026quot;; font-size: 14.5pt;\"\u003E\u003Co:p\u003E\u003C\/o:p\u003E\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white; margin-bottom: 11.25pt; margin-left: 0in; margin-right: 0in; margin-top: 3.75pt;\"\u003E\n\u003C\/div\u003E\n\u003Cdiv class=\"MsoNormal\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv style=\"background: white; margin-bottom: 11.25pt; margin-left: 0in; margin-right: 0in; margin-top: 3.75pt;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n"},"link":[{"rel":"replies","type":"application/atom+xml","href":"https:\/\/javaonfly.blogspot.com\/feeds\/4865068112119011518\/comments\/default","title":"Post Comments"},{"rel":"replies","type":"text/html","href":"https:\/\/javaonfly.blogspot.com\/2019\/05\/effective-advice-on-spring-async-final.html#comment-form","title":"0 Comments"},{"rel":"edit","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/1902220484592789830\/posts\/default\/4865068112119011518"},{"rel":"self","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/1902220484592789830\/posts\/default\/4865068112119011518"},{"rel":"alternate","type":"text/html","href":"https:\/\/javaonfly.blogspot.com\/2019\/05\/effective-advice-on-spring-async-final.html","title":"Effective Advice on Spring @Async : Final Part ."}],"author":[{"name":{"$t":"Shamik Mitra"},"uri":{"$t":"http:\/\/www.blogger.com\/profile\/02620539092954103493"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"32","height":"32","src":"\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEjO2_A4uqRhlGdVcT56_sL024d9he6fReKq6CmpVwX7qqUKgBabEnhONHd9y8oFkNxgq80hXHMuC0mPAGRbIVw97aE63F0pwKB7fEKo397jRnCXRsc_1S1Px7VJSxmIsts\/s113\/534152_10200300633532106_2101616363_n.jpg"}}],"media$thumbnail":{"xmlns$media":"http://search.yahoo.com/mrss/","url":"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEjMVGOyPZmwduOnSqt0nEFNQu7jszJWeAT2alPxarkBEzEmjLJcza0-j3wU9nVIwp5jcp5dNr88vN5RaEIMLdeJmNK1oNARSfkWVvKKxQh5WPD0YhaHgEZCCu-fLnoESWxP-zoPn3RCWnM\/s72-c\/AsyncusgaeInSpringBoot.jpg","height":"72","width":"72"},"thr$total":{"$t":"0"}},{"id":{"$t":"tag:blogger.com,1999:blog-1902220484592789830.post-1381221667007758338"},"published":{"$t":"2019-03-24T13:59:00.000+05:30"},"updated":{"$t":"2019-05-04T20:25:12.513+05:30"},"category":[{"scheme":"http://www.blogger.com/atom/ns#","term":"java interview"},{"scheme":"http://www.blogger.com/atom/ns#","term":"spring"},{"scheme":"http://www.blogger.com/atom/ns#","term":"SpringAsync"}],"title":{"type":"text","$t":"Effective Advice on Spring @Async (ExceptionHandler): Part 2"},"content":{"type":"html","$t":"\u003Cdiv dir=\"ltr\" style=\"text-align: left;\" trbidi=\"on\"\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ca href=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEjGpT0EkSlkVIWPQ46feOC-pCgDUfbRR76eOq7UzReebYl1U6m99YlVvfsbShxEGAezv5JkdyOGRILpvdBggdhHtIKX7xp0AF_reqPoZW8hej93trFo8rKq82FyApjOANGrUl0goOt1cv0\/s1600\/SpringAsyncpart2.jpg\" imageanchor=\"1\" style=\"clear: left; float: left; margin-bottom: 1em; margin-right: 1em;\"\u003E\u003Cimg border=\"0\" data-original-height=\"625\" data-original-width=\"1000\" height=\"200\" src=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEjGpT0EkSlkVIWPQ46feOC-pCgDUfbRR76eOq7UzReebYl1U6m99YlVvfsbShxEGAezv5JkdyOGRILpvdBggdhHtIKX7xp0AF_reqPoZW8hej93trFo8rKq82FyApjOANGrUl0goOt1cv0\/s320\/SpringAsyncpart2.jpg\" width=\"320\" \/\u003E\u003C\/a\u003E\u003C\/div\u003E\nIn this article, I am going to discuss, how to catch Exception while you are using @Async annotation with Spring boot. Before deep diving to Exception handler I hope everyone who is reading this article, read my first part, If not I encourage you to do so, here is the link.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nWhile you are forking thread from the main thread possibly you have two options.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n1. \u003Cb\u003EFire and forget\u003C\/b\u003E :: you just fork a thread , assign some work to that thread, and just forget, at this moment,\u0026nbsp; you do not bother with the outcome as you do not need this information in order to execute next business logic, generally it's return type is void, let's understand with an example, Say you are in a process of\u0026nbsp; sending salary to the employees,\u0026nbsp; as a part of that you send an email to each employee attaching respective salary slip, and you do it asynchronously. Obviously sending salary slip via email to the employee is not a part of your core business logic, it is a cross-cutting concern, it is a good to have a feature(Some cases it is must have, then you adopt retrying, or schedule mechanism) rather than must to have.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n2. \u003Cb\u003EFire with Callback\u003C\/b\u003E:: Here you fork a thread from the main thread and assign some work to that thread then attach a Callback. After that, the main thread proceeds with other tasks but the main thread keeps checking the callback for the result. The main thread needs that outcome from sub-thread as a form of callback to execute further.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nSay you are preparing an Employee report,\u0026nbsp; Your software stores employee information in different backends based on the data category. , say General Service hold Employees general data (name, birthday, sex, address) and financial service holds(Salary, Tax, PF related data), so you fork two threads parallelly one for general service one for financial service, but you need both data to proceed further as in the report you need to combine both the data. So in the main thread, you want those results as a callback from subthreads, generally, we do it by CompletebleFuture(read Callable with Future).\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nIn the above scenarios, if all is well that is the ideal case, but in the real-time exception can happen, then how you will handle Exception in the above two scenarios?\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nIn the second scenario, It is very easy as result comes as a callback, whatever the result it is(Success or Failure), in case of failure,\u0026nbsp; Exception wrapped inside CompltebleFuture you can check the same and handle it in the main thread. Not a big deal,\u0026nbsp; basic java code. So I will skip that.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nBut Scenario one is tricky, you fork a thread with some business case,\u0026nbsp; how you can be sure that is a success, or if that is failure how you will debug it, how you will get a trace that something goes wrong?\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nThe solution is very simple, You need to inject your own Exception handler so that if an exception occurs while you are executing an Async method it should pass the control to that handler and then handles what to do with that,\u0026nbsp; very Simple isn't it.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nTo achieve that we need to follow below steps.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n1. \u003Cb\u003EAsyncConfigurer\u003C\/b\u003E::\u0026nbsp; AsyncConfigurere is an Interface provided by Spring, It provides two methods one is if you want to override the TaskExecutor(Threadpool) another is an Exception handler where you can inject your exception handler so it can catch the uncaught exceptions. You can create your own class and implements that one directly. but I will not do that, as an alternative, I will use Spring\u0026nbsp; AsyncConfigurerSupport class which annotates by @Configuration and @EnableAsync, and provides a default implementation.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003Epackage com.example.ask2shamik.springAsync;\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003E\u003Cbr \/\u003E\u003C\/span\u003E\n\u003Cspan style=\"color: blue;\"\u003Eimport java.lang.reflect.Method;\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003Eimport java.util.concurrent.Executor;\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003E\u003Cbr \/\u003E\u003C\/span\u003E\n\u003Cspan style=\"color: blue;\"\u003Eimport org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003Eimport org.springframework.context.annotation.Configuration;\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003Eimport org.springframework.core.task.SimpleAsyncTaskExecutor;\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003Eimport org.springframework.lang.Nullable;\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003Eimport org.springframework.scheduling.annotation.AsyncConfigurerSupport;\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003Eimport org.springframework.scheduling.annotation.EnableAsync;\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003E\u003Cbr \/\u003E\u003C\/span\u003E\n\u003Cspan style=\"color: blue;\"\u003E\u003Cbr \/\u003E\u003C\/span\u003E\n\u003Cspan style=\"color: blue;\"\u003E\u003Cbr \/\u003E\u003C\/span\u003E\n\u003Cspan style=\"color: blue;\"\u003E@Configuration\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003E@EnableAsync\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003Epublic class CustomConfiguration extends AsyncConfigurerSupport {\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003E@Override\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003Epublic Executor getAsyncExecutor() {\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003Ereturn new SimpleAsyncTaskExecutor();\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003E}\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003E\u003Cbr \/\u003E\u003C\/span\u003E\n\u003Cspan style=\"color: blue;\"\u003E\u003Cbr \/\u003E\u003C\/span\u003E\n\u003Cspan style=\"color: blue;\"\u003E@Override\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003E@Nullable\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003Epublic AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003E\u003Cbr \/\u003E\u003C\/span\u003E\n\u003Cspan style=\"color: blue;\"\u003Ereturn (throwable, method, obj)-\u0026gt;{\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003ESystem.out.println(\"Exception Caught in Thread - \" + Thread.currentThread().getName());\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003ESystem.out.println(\"Exception message - \" + throwable.getMessage());\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003ESystem.out.println(\"Method name - \" + method.getName());\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003Efor (Object param : obj) {\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003ESystem.out.println(\"Parameter value - \" + param);\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003E}\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003E};\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003E}\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003E\u003Cbr \/\u003E\u003C\/span\u003E\n\u003Cspan style=\"color: blue;\"\u003E}\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nPlease note that, In case of, \u003Cb\u003EgetAsyncExecutor \u003C\/b\u003Emethod, I am not going to create any new Executor as I do not want to use my own task executor so I use Spring default \u003Cb\u003ESimpleAsyncExecutor\u003C\/b\u003E.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nBut\u0026nbsp; I need my custom uncaught exception handler to handle any uncaught Exception so I create a lambda expression which actually extends\u0026nbsp; \u003Cb\u003EAsyncUncaughtExceptionHandler \u003C\/b\u003Eclass and overrides \u003Cb\u003Ehandleuncaughtexception \u003C\/b\u003Emethod.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nIn this way, I instruct Spring while loading, use my application specific AsyncConfugurer(\u003Cb\u003ECustomConfiguration\u003C\/b\u003E)\u0026nbsp; and use my lambda expression as an Exception handler.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nNow I create an async method which will throw an Exception.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003Epackage com.example.ask2shamik.springAsync.demo;\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003E\u003Cbr \/\u003E\u003C\/span\u003E\n\u003Cspan style=\"color: blue;\"\u003Eimport java.util.Map;\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003E\u003Cbr \/\u003E\u003C\/span\u003E\n\u003Cspan style=\"color: blue;\"\u003Eimport org.springframework.scheduling.annotation.Async;\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003Eimport org.springframework.stereotype.Component;\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003E@Component\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003Epublic class AsyncMailTrigger {\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003E\u003Cbr \/\u003E\u003C\/span\u003E\n\u003Cspan style=\"color: blue;\"\u003E@Async\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003Epublic void senMailwithException() throws Exception{\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003Ethrow new Exception(\"SMTP Server not found :: orginated from Thread :: \" + Thread.currentThread().getName());\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003E\u003Cbr \/\u003E\u003C\/span\u003E\n\u003Cspan style=\"color: blue;\"\u003E}\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003E\u003Cbr \/\u003E\u003C\/span\u003E\n\u003Cspan style=\"color: blue;\"\u003E}\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nNow, Create a caller method.\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003Epackage com.example.ask2shamik.springAsync.demo;\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003E\u003Cbr \/\u003E\u003C\/span\u003E\n\u003Cspan style=\"color: blue;\"\u003Eimport java.util.HashMap;\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003Eimport java.util.Map;\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003E\u003Cbr \/\u003E\u003C\/span\u003E\n\u003Cspan style=\"color: blue;\"\u003Eimport org.springframework.beans.factory.annotation.Autowired;\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003Eimport org.springframework.scheduling.annotation.Async;\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003Eimport org.springframework.stereotype.Component;\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003E@Component\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003Epublic class AsyncCaller {\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003E\u003Cbr \/\u003E\u003C\/span\u003E\n\u003Cspan style=\"color: blue;\"\u003E@Autowired\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003EAsyncMailTrigger asyncMailTriggerObject;\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003E\u003Cbr \/\u003E\u003C\/span\u003E\n\u003Cspan style=\"color: blue;\"\u003Epublic void rightWayToCall() throws Exception {\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003ESystem.out.println(\"Calling From rightWayToCall Thread \" + Thread.currentThread().getName());\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003EasyncMailTriggerObject.senMailwithException();\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003E\u003Cbr \/\u003E\u003C\/span\u003E\n\u003Cspan style=\"color: blue;\"\u003E}\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003E\u003Cbr \/\u003E\u003C\/span\u003E\n\u003Cspan style=\"color: blue;\"\u003E}\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nNow let's run this Application using Spring boot, to see How it catch the Exception thrown by the method sendMailwithException.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003Epackage com.example.ask2shamik.springAsync;\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003E\u003Cbr \/\u003E\u003C\/span\u003E\n\u003Cspan style=\"color: blue;\"\u003Eimport org.springframework.beans.factory.annotation.Autowired;\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003Eimport org.springframework.boot.CommandLineRunner;\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003Eimport org.springframework.boot.SpringApplication;\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003Eimport org.springframework.boot.autoconfigure.SpringBootApplication;\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003Eimport org.springframework.context.ApplicationContext;\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003Eimport org.springframework.context.annotation.Bean;\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003Eimport org.springframework.scheduling.annotation.EnableAsync;\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003E\u003Cbr \/\u003E\u003C\/span\u003E\n\u003Cspan style=\"color: blue;\"\u003Eimport com.example.ask2shamik.springAsync.demo.AsyncCaller;\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003E\u003Cbr \/\u003E\u003C\/span\u003E\n\u003Cspan style=\"color: blue;\"\u003E@SpringBootApplication\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003Epublic class DemoApplication {\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003E\u003Cbr \/\u003E\u003C\/span\u003E\n\u003Cspan style=\"color: blue;\"\u003E@Autowired\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003EAsyncCaller caller;\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003E\u003Cbr \/\u003E\u003C\/span\u003E\n\u003Cspan style=\"color: blue;\"\u003Epublic static void main(String[] args) {\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003ESpringApplication.run(DemoApplication.class, args);\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003E\u003Cbr \/\u003E\u003C\/span\u003E\n\u003Cspan style=\"color: blue;\"\u003E}\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003E\u0026nbsp;@Bean\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003E\u0026nbsp;public CommandLineRunner commandLineRunner(ApplicationContext ctx) {\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003E\u0026nbsp; \u0026nbsp; \u0026nbsp; \u0026nbsp; return args -\u0026gt; {\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003E\u0026nbsp; \u0026nbsp; \u0026nbsp; \u0026nbsp; caller.rightWayToCall();\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003E\u0026nbsp; \u0026nbsp; \u0026nbsp; \u0026nbsp; \u0026nbsp;};\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003E\u0026nbsp; \u0026nbsp; }\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003E\u003Cbr \/\u003E\u003C\/span\u003E\n\u003Cspan style=\"color: blue;\"\u003E\u003Cbr \/\u003E\u003C\/span\u003E\n\u003Cspan style=\"color: blue;\"\u003E}\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nAnd the output is\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003ECalling From rightWayToCall Thread main\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003EException Caught in Thread - SimpleAsyncTaskExecutor-1\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003EException message - SMTP Server not found:: originated from Thread:: SimpleAsyncTaskExecutor-1\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"color: blue;\"\u003EMethod name - senMailwithException\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003EConclusion\u003C\/b\u003E: Hope you like the tutorial, If you have a question please put it in the comment box and stay tuned for part 3.\u003C\/div\u003E\n"},"link":[{"rel":"replies","type":"application/atom+xml","href":"https:\/\/javaonfly.blogspot.com\/feeds\/1381221667007758338\/comments\/default","title":"Post Comments"},{"rel":"replies","type":"text/html","href":"https:\/\/javaonfly.blogspot.com\/2019\/03\/SpringAsyncExceptionHandler.html#comment-form","title":"1 Comments"},{"rel":"edit","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/1902220484592789830\/posts\/default\/1381221667007758338"},{"rel":"self","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/1902220484592789830\/posts\/default\/1381221667007758338"},{"rel":"alternate","type":"text/html","href":"https:\/\/javaonfly.blogspot.com\/2019\/03\/SpringAsyncExceptionHandler.html","title":"Effective Advice on Spring @Async (ExceptionHandler): Part 2"}],"author":[{"name":{"$t":"Shamik Mitra"},"uri":{"$t":"http:\/\/www.blogger.com\/profile\/02620539092954103493"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"32","height":"32","src":"\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEjO2_A4uqRhlGdVcT56_sL024d9he6fReKq6CmpVwX7qqUKgBabEnhONHd9y8oFkNxgq80hXHMuC0mPAGRbIVw97aE63F0pwKB7fEKo397jRnCXRsc_1S1Px7VJSxmIsts\/s113\/534152_10200300633532106_2101616363_n.jpg"}}],"media$thumbnail":{"xmlns$media":"http://search.yahoo.com/mrss/","url":"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEjGpT0EkSlkVIWPQ46feOC-pCgDUfbRR76eOq7UzReebYl1U6m99YlVvfsbShxEGAezv5JkdyOGRILpvdBggdhHtIKX7xp0AF_reqPoZW8hej93trFo8rKq82FyApjOANGrUl0goOt1cv0\/s72-c\/SpringAsyncpart2.jpg","height":"72","width":"72"},"thr$total":{"$t":"1"}}]}});