[{"data":1,"prerenderedAt":10649},["ShallowReactive",2],{"tag-java":3},[4,955,1778,2802,3654,5441,6690,7710,8104,8738],{"_path":5,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":9,"description":10,"date":11,"layout":12,"subtitle":13,"image":14,"optimized_image":14,"category":15,"tags":16,"author":21,"paginate":7,"body":22,"_type":949,"_id":950,"_source":951,"_file":952,"_stem":953,"_extension":954},"/posts/java-security-best-practices","posts",false,"","Java Security Best Practices: Preventing Vulnerabilities and Threats","Explore essential security strategies for Java applications, addressing common vulnerabilities identified by OWASP Top 10 with practical examples.","2024-08-15T11:00:00.000Z","post","Practical Strategies to Safeguard Your Java Applications","/assets/img/uploads/java-security-best-practices.png","code",[15,17,18,19,20],"java","security","owasp","cybersecurity","jaimedearcos",{"type":23,"children":24,"toc":937},"root",[25,37,44,49,104,109,115,120,257,262,268,273,381,387,392,515,520,526,531,556,561,567,572,588,593,599,604,687,692,698,703,823,828,834,839,872,877,883,888,895,931],{"type":26,"tag":27,"props":28,"children":29},"element","blockquote",{},[30],{"type":26,"tag":31,"props":32,"children":33},"p",{},[34],{"type":35,"value":36},"text","Security is critical in software development. Java applications, like all software, face numerous potential vulnerabilities. In this article, we will explore essential security best practices, referencing the OWASP Top 10, and providing practical Java examples to help you protect your applications effectively.",{"type":26,"tag":38,"props":39,"children":41},"h2",{"id":40},"understanding-owasp-top-10",[42],{"type":35,"value":43},"Understanding OWASP Top 10",{"type":26,"tag":31,"props":45,"children":46},{},[47],{"type":35,"value":48},"The OWASP Top 10 outlines the most critical web application security risks:",{"type":26,"tag":50,"props":51,"children":52},"ol",{},[53,59,64,69,74,79,84,89,94,99],{"type":26,"tag":54,"props":55,"children":56},"li",{},[57],{"type":35,"value":58},"Injection",{"type":26,"tag":54,"props":60,"children":61},{},[62],{"type":35,"value":63},"Broken Authentication",{"type":26,"tag":54,"props":65,"children":66},{},[67],{"type":35,"value":68},"Sensitive Data Exposure",{"type":26,"tag":54,"props":70,"children":71},{},[72],{"type":35,"value":73},"XML External Entities (XXE)",{"type":26,"tag":54,"props":75,"children":76},{},[77],{"type":35,"value":78},"Broken Access Control",{"type":26,"tag":54,"props":80,"children":81},{},[82],{"type":35,"value":83},"Security Misconfiguration",{"type":26,"tag":54,"props":85,"children":86},{},[87],{"type":35,"value":88},"Cross-Site Scripting (XSS)",{"type":26,"tag":54,"props":90,"children":91},{},[92],{"type":35,"value":93},"Insecure Deserialization",{"type":26,"tag":54,"props":95,"children":96},{},[97],{"type":35,"value":98},"Using Components with Known Vulnerabilities",{"type":26,"tag":54,"props":100,"children":101},{},[102],{"type":35,"value":103},"Insufficient Logging and Monitoring",{"type":26,"tag":31,"props":105,"children":106},{},[107],{"type":35,"value":108},"Let's delve into practical strategies and Java implementations for some of these threats.",{"type":26,"tag":38,"props":110,"children":112},{"id":111},"_1-injection-prevention",[113],{"type":35,"value":114},"1. Injection Prevention",{"type":26,"tag":31,"props":116,"children":117},{},[118],{"type":35,"value":119},"Use Prepared Statements and parameterized queries:",{"type":26,"tag":121,"props":122,"children":125},"pre",{"className":123,"code":124,"language":17,"meta":8,"style":8},"language-java shiki shiki-themes github-dark github-light","PreparedStatement stmt = connection.prepareStatement(\"SELECT * FROM users WHERE username=? AND password=?\");\nstmt.setString(1, username);\nstmt.setString(2, password);\nResultSet rs = stmt.executeQuery();\n",[126],{"type":26,"tag":15,"props":127,"children":128},{"__ignoreMap":8},[129,174,203,229],{"type":26,"tag":130,"props":131,"children":134},"span",{"class":132,"line":133},"line",1,[135,141,147,152,158,163,169],{"type":26,"tag":130,"props":136,"children":138},{"style":137},"--shiki-default:#E1E4E8;--shiki-light:#24292E",[139],{"type":35,"value":140},"PreparedStatement stmt ",{"type":26,"tag":130,"props":142,"children":144},{"style":143},"--shiki-default:#F97583;--shiki-light:#D73A49",[145],{"type":35,"value":146},"=",{"type":26,"tag":130,"props":148,"children":149},{"style":137},[150],{"type":35,"value":151}," connection.",{"type":26,"tag":130,"props":153,"children":155},{"style":154},"--shiki-default:#B392F0;--shiki-light:#6F42C1",[156],{"type":35,"value":157},"prepareStatement",{"type":26,"tag":130,"props":159,"children":160},{"style":137},[161],{"type":35,"value":162},"(",{"type":26,"tag":130,"props":164,"children":166},{"style":165},"--shiki-default:#9ECBFF;--shiki-light:#032F62",[167],{"type":35,"value":168},"\"SELECT * FROM users WHERE username=? AND password=?\"",{"type":26,"tag":130,"props":170,"children":171},{"style":137},[172],{"type":35,"value":173},");\n",{"type":26,"tag":130,"props":175,"children":177},{"class":132,"line":176},2,[178,183,188,192,198],{"type":26,"tag":130,"props":179,"children":180},{"style":137},[181],{"type":35,"value":182},"stmt.",{"type":26,"tag":130,"props":184,"children":185},{"style":154},[186],{"type":35,"value":187},"setString",{"type":26,"tag":130,"props":189,"children":190},{"style":137},[191],{"type":35,"value":162},{"type":26,"tag":130,"props":193,"children":195},{"style":194},"--shiki-default:#79B8FF;--shiki-light:#005CC5",[196],{"type":35,"value":197},"1",{"type":26,"tag":130,"props":199,"children":200},{"style":137},[201],{"type":35,"value":202},", username);\n",{"type":26,"tag":130,"props":204,"children":206},{"class":132,"line":205},3,[207,211,215,219,224],{"type":26,"tag":130,"props":208,"children":209},{"style":137},[210],{"type":35,"value":182},{"type":26,"tag":130,"props":212,"children":213},{"style":154},[214],{"type":35,"value":187},{"type":26,"tag":130,"props":216,"children":217},{"style":137},[218],{"type":35,"value":162},{"type":26,"tag":130,"props":220,"children":221},{"style":194},[222],{"type":35,"value":223},"2",{"type":26,"tag":130,"props":225,"children":226},{"style":137},[227],{"type":35,"value":228},", password);\n",{"type":26,"tag":130,"props":230,"children":232},{"class":132,"line":231},4,[233,238,242,247,252],{"type":26,"tag":130,"props":234,"children":235},{"style":137},[236],{"type":35,"value":237},"ResultSet rs ",{"type":26,"tag":130,"props":239,"children":240},{"style":143},[241],{"type":35,"value":146},{"type":26,"tag":130,"props":243,"children":244},{"style":137},[245],{"type":35,"value":246}," stmt.",{"type":26,"tag":130,"props":248,"children":249},{"style":154},[250],{"type":35,"value":251},"executeQuery",{"type":26,"tag":130,"props":253,"children":254},{"style":137},[255],{"type":35,"value":256},"();\n",{"type":26,"tag":31,"props":258,"children":259},{},[260],{"type":35,"value":261},"This approach prevents SQL injection by ensuring that input data is treated as data, not executable code.",{"type":26,"tag":38,"props":263,"children":265},{"id":264},"_2-secure-authentication",[266],{"type":35,"value":267},"2. Secure Authentication",{"type":26,"tag":31,"props":269,"children":270},{},[271],{"type":35,"value":272},"Implement robust authentication using secure password storage (bcrypt or Argon2):",{"type":26,"tag":121,"props":274,"children":276},{"className":123,"code":275,"language":17,"meta":8,"style":8},"import org.springframework.security.crypto.bcrypt.BCrypt;\n\nString hashedPassword = BCrypt.hashpw(password, BCrypt.gensalt());\nif (BCrypt.checkpw(password, hashedPassword)) {\n    // authentication successful\n}\n",[277],{"type":26,"tag":15,"props":278,"children":279},{"__ignoreMap":8},[280,293,302,339,362,372],{"type":26,"tag":130,"props":281,"children":282},{"class":132,"line":133},[283,288],{"type":26,"tag":130,"props":284,"children":285},{"style":143},[286],{"type":35,"value":287},"import",{"type":26,"tag":130,"props":289,"children":290},{"style":137},[291],{"type":35,"value":292}," org.springframework.security.crypto.bcrypt.BCrypt;\n",{"type":26,"tag":130,"props":294,"children":295},{"class":132,"line":176},[296],{"type":26,"tag":130,"props":297,"children":299},{"emptyLinePlaceholder":298},true,[300],{"type":35,"value":301},"\n",{"type":26,"tag":130,"props":303,"children":304},{"class":132,"line":205},[305,310,314,319,324,329,334],{"type":26,"tag":130,"props":306,"children":307},{"style":137},[308],{"type":35,"value":309},"String hashedPassword ",{"type":26,"tag":130,"props":311,"children":312},{"style":143},[313],{"type":35,"value":146},{"type":26,"tag":130,"props":315,"children":316},{"style":137},[317],{"type":35,"value":318}," BCrypt.",{"type":26,"tag":130,"props":320,"children":321},{"style":154},[322],{"type":35,"value":323},"hashpw",{"type":26,"tag":130,"props":325,"children":326},{"style":137},[327],{"type":35,"value":328},"(password, BCrypt.",{"type":26,"tag":130,"props":330,"children":331},{"style":154},[332],{"type":35,"value":333},"gensalt",{"type":26,"tag":130,"props":335,"children":336},{"style":137},[337],{"type":35,"value":338},"());\n",{"type":26,"tag":130,"props":340,"children":341},{"class":132,"line":231},[342,347,352,357],{"type":26,"tag":130,"props":343,"children":344},{"style":143},[345],{"type":35,"value":346},"if",{"type":26,"tag":130,"props":348,"children":349},{"style":137},[350],{"type":35,"value":351}," (BCrypt.",{"type":26,"tag":130,"props":353,"children":354},{"style":154},[355],{"type":35,"value":356},"checkpw",{"type":26,"tag":130,"props":358,"children":359},{"style":137},[360],{"type":35,"value":361},"(password, hashedPassword)) {\n",{"type":26,"tag":130,"props":363,"children":365},{"class":132,"line":364},5,[366],{"type":26,"tag":130,"props":367,"children":369},{"style":368},"--shiki-default:#6A737D;--shiki-light:#6A737D",[370],{"type":35,"value":371},"    // authentication successful\n",{"type":26,"tag":130,"props":373,"children":375},{"class":132,"line":374},6,[376],{"type":26,"tag":130,"props":377,"children":378},{"style":137},[379],{"type":35,"value":380},"}\n",{"type":26,"tag":38,"props":382,"children":384},{"id":383},"_3-sensitive-data-exposure",[385],{"type":35,"value":386},"3. Sensitive Data Exposure",{"type":26,"tag":31,"props":388,"children":389},{},[390],{"type":35,"value":391},"Use encryption for sensitive data storage:",{"type":26,"tag":121,"props":393,"children":395},{"className":123,"code":394,"language":17,"meta":8,"style":8},"Cipher cipher = Cipher.getInstance(\"AES/GCM/NoPadding\");\nSecretKey key = generateSecretKey();\ncipher.init(Cipher.ENCRYPT_MODE, key);\nbyte[] encryptedData = cipher.doFinal(plainData.getBytes(StandardCharsets.UTF_8));\n",[396],{"type":26,"tag":15,"props":397,"children":398},{"__ignoreMap":8},[399,434,455,473],{"type":26,"tag":130,"props":400,"children":401},{"class":132,"line":133},[402,407,411,416,421,425,430],{"type":26,"tag":130,"props":403,"children":404},{"style":137},[405],{"type":35,"value":406},"Cipher cipher ",{"type":26,"tag":130,"props":408,"children":409},{"style":143},[410],{"type":35,"value":146},{"type":26,"tag":130,"props":412,"children":413},{"style":137},[414],{"type":35,"value":415}," Cipher.",{"type":26,"tag":130,"props":417,"children":418},{"style":154},[419],{"type":35,"value":420},"getInstance",{"type":26,"tag":130,"props":422,"children":423},{"style":137},[424],{"type":35,"value":162},{"type":26,"tag":130,"props":426,"children":427},{"style":165},[428],{"type":35,"value":429},"\"AES/GCM/NoPadding\"",{"type":26,"tag":130,"props":431,"children":432},{"style":137},[433],{"type":35,"value":173},{"type":26,"tag":130,"props":435,"children":436},{"class":132,"line":176},[437,442,446,451],{"type":26,"tag":130,"props":438,"children":439},{"style":137},[440],{"type":35,"value":441},"SecretKey key ",{"type":26,"tag":130,"props":443,"children":444},{"style":143},[445],{"type":35,"value":146},{"type":26,"tag":130,"props":447,"children":448},{"style":154},[449],{"type":35,"value":450}," generateSecretKey",{"type":26,"tag":130,"props":452,"children":453},{"style":137},[454],{"type":35,"value":256},{"type":26,"tag":130,"props":456,"children":457},{"class":132,"line":205},[458,463,468],{"type":26,"tag":130,"props":459,"children":460},{"style":137},[461],{"type":35,"value":462},"cipher.",{"type":26,"tag":130,"props":464,"children":465},{"style":154},[466],{"type":35,"value":467},"init",{"type":26,"tag":130,"props":469,"children":470},{"style":137},[471],{"type":35,"value":472},"(Cipher.ENCRYPT_MODE, key);\n",{"type":26,"tag":130,"props":474,"children":475},{"class":132,"line":231},[476,481,486,490,495,500,505,510],{"type":26,"tag":130,"props":477,"children":478},{"style":143},[479],{"type":35,"value":480},"byte",{"type":26,"tag":130,"props":482,"children":483},{"style":137},[484],{"type":35,"value":485},"[] encryptedData ",{"type":26,"tag":130,"props":487,"children":488},{"style":143},[489],{"type":35,"value":146},{"type":26,"tag":130,"props":491,"children":492},{"style":137},[493],{"type":35,"value":494}," cipher.",{"type":26,"tag":130,"props":496,"children":497},{"style":154},[498],{"type":35,"value":499},"doFinal",{"type":26,"tag":130,"props":501,"children":502},{"style":137},[503],{"type":35,"value":504},"(plainData.",{"type":26,"tag":130,"props":506,"children":507},{"style":154},[508],{"type":35,"value":509},"getBytes",{"type":26,"tag":130,"props":511,"children":512},{"style":137},[513],{"type":35,"value":514},"(StandardCharsets.UTF_8));\n",{"type":26,"tag":31,"props":516,"children":517},{},[518],{"type":35,"value":519},"Always encrypt data at rest and in transit (use HTTPS).",{"type":26,"tag":38,"props":521,"children":523},{"id":522},"_4-security-misconfiguration",[524],{"type":35,"value":525},"4. Security Misconfiguration",{"type":26,"tag":31,"props":527,"children":528},{},[529],{"type":35,"value":530},"Adopt secure defaults, disable debugging, and avoid detailed error messages:",{"type":26,"tag":121,"props":532,"children":536},{"className":533,"code":534,"language":535,"meta":8,"style":8},"language-properties shiki shiki-themes github-dark github-light","server.error.include-stacktrace=never\nserver.error.include-message=never\n","properties",[537],{"type":26,"tag":15,"props":538,"children":539},{"__ignoreMap":8},[540,548],{"type":26,"tag":130,"props":541,"children":542},{"class":132,"line":133},[543],{"type":26,"tag":130,"props":544,"children":545},{},[546],{"type":35,"value":547},"server.error.include-stacktrace=never\n",{"type":26,"tag":130,"props":549,"children":550},{"class":132,"line":176},[551],{"type":26,"tag":130,"props":552,"children":553},{},[554],{"type":35,"value":555},"server.error.include-message=never\n",{"type":26,"tag":31,"props":557,"children":558},{},[559],{"type":35,"value":560},"Review and secure your Java application configuration regularly.",{"type":26,"tag":38,"props":562,"children":564},{"id":563},"_5-cross-site-scripting-xss",[565],{"type":35,"value":566},"5. Cross-Site Scripting (XSS)",{"type":26,"tag":31,"props":568,"children":569},{},[570],{"type":35,"value":571},"Utilize proper encoding or frameworks that prevent XSS by default, such as Thymeleaf:",{"type":26,"tag":121,"props":573,"children":577},{"className":574,"code":575,"language":576,"meta":8,"style":8},"language-html shiki shiki-themes github-dark github-light","\u003Cp th:text=\"${userInput}\">\u003C/p>\n","html",[578],{"type":26,"tag":15,"props":579,"children":580},{"__ignoreMap":8},[581],{"type":26,"tag":130,"props":582,"children":583},{"class":132,"line":133},[584],{"type":26,"tag":130,"props":585,"children":586},{},[587],{"type":35,"value":575},{"type":26,"tag":31,"props":589,"children":590},{},[591],{"type":35,"value":592},"Avoid directly inserting user inputs into HTML without proper sanitization or encoding.",{"type":26,"tag":38,"props":594,"children":596},{"id":595},"_6-insecure-deserialization",[597],{"type":35,"value":598},"6. Insecure Deserialization",{"type":26,"tag":31,"props":600,"children":601},{},[602],{"type":35,"value":603},"Limit deserialization to trusted sources only:",{"type":26,"tag":121,"props":605,"children":607},{"className":123,"code":606,"language":17,"meta":8,"style":8},"ObjectInputStream ois = new ObjectInputStream(new FileInputStream(\"trusted_data.ser\"));\nMyObject obj = (MyObject) ois.readObject();\n",[608],{"type":26,"tag":15,"props":609,"children":610},{"__ignoreMap":8},[611,661],{"type":26,"tag":130,"props":612,"children":613},{"class":132,"line":133},[614,619,623,628,633,637,642,647,651,656],{"type":26,"tag":130,"props":615,"children":616},{"style":137},[617],{"type":35,"value":618},"ObjectInputStream ois ",{"type":26,"tag":130,"props":620,"children":621},{"style":143},[622],{"type":35,"value":146},{"type":26,"tag":130,"props":624,"children":625},{"style":143},[626],{"type":35,"value":627}," new",{"type":26,"tag":130,"props":629,"children":630},{"style":154},[631],{"type":35,"value":632}," ObjectInputStream",{"type":26,"tag":130,"props":634,"children":635},{"style":137},[636],{"type":35,"value":162},{"type":26,"tag":130,"props":638,"children":639},{"style":143},[640],{"type":35,"value":641},"new",{"type":26,"tag":130,"props":643,"children":644},{"style":154},[645],{"type":35,"value":646}," FileInputStream",{"type":26,"tag":130,"props":648,"children":649},{"style":137},[650],{"type":35,"value":162},{"type":26,"tag":130,"props":652,"children":653},{"style":165},[654],{"type":35,"value":655},"\"trusted_data.ser\"",{"type":26,"tag":130,"props":657,"children":658},{"style":137},[659],{"type":35,"value":660},"));\n",{"type":26,"tag":130,"props":662,"children":663},{"class":132,"line":176},[664,669,673,678,683],{"type":26,"tag":130,"props":665,"children":666},{"style":137},[667],{"type":35,"value":668},"MyObject obj ",{"type":26,"tag":130,"props":670,"children":671},{"style":143},[672],{"type":35,"value":146},{"type":26,"tag":130,"props":674,"children":675},{"style":137},[676],{"type":35,"value":677}," (MyObject) ois.",{"type":26,"tag":130,"props":679,"children":680},{"style":154},[681],{"type":35,"value":682},"readObject",{"type":26,"tag":130,"props":684,"children":685},{"style":137},[686],{"type":35,"value":256},{"type":26,"tag":31,"props":688,"children":689},{},[690],{"type":35,"value":691},"Always validate deserialized data.",{"type":26,"tag":38,"props":693,"children":695},{"id":694},"_7-component-vulnerabilities",[696],{"type":35,"value":697},"7. Component Vulnerabilities",{"type":26,"tag":31,"props":699,"children":700},{},[701],{"type":35,"value":702},"Regularly update libraries and dependencies, and use tools like OWASP Dependency-Check to identify vulnerabilities:",{"type":26,"tag":121,"props":704,"children":708},{"className":705,"code":706,"language":707,"meta":8,"style":8},"language-xml shiki shiki-themes github-dark github-light","\u003Cplugin>\n    \u003CgroupId>org.owasp\u003C/groupId>\n    \u003CartifactId>dependency-check-maven\u003C/artifactId>\n    \u003Cversion>9.0.9\u003C/version>\n\u003C/plugin>\n","xml",[709],{"type":26,"tag":15,"props":710,"children":711},{"__ignoreMap":8},[712,731,757,782,807],{"type":26,"tag":130,"props":713,"children":714},{"class":132,"line":133},[715,720,726],{"type":26,"tag":130,"props":716,"children":717},{"style":137},[718],{"type":35,"value":719},"\u003C",{"type":26,"tag":130,"props":721,"children":723},{"style":722},"--shiki-default:#85E89D;--shiki-light:#22863A",[724],{"type":35,"value":725},"plugin",{"type":26,"tag":130,"props":727,"children":728},{"style":137},[729],{"type":35,"value":730},">\n",{"type":26,"tag":130,"props":732,"children":733},{"class":132,"line":176},[734,739,744,749,753],{"type":26,"tag":130,"props":735,"children":736},{"style":137},[737],{"type":35,"value":738},"    \u003C",{"type":26,"tag":130,"props":740,"children":741},{"style":722},[742],{"type":35,"value":743},"groupId",{"type":26,"tag":130,"props":745,"children":746},{"style":137},[747],{"type":35,"value":748},">org.owasp\u003C/",{"type":26,"tag":130,"props":750,"children":751},{"style":722},[752],{"type":35,"value":743},{"type":26,"tag":130,"props":754,"children":755},{"style":137},[756],{"type":35,"value":730},{"type":26,"tag":130,"props":758,"children":759},{"class":132,"line":205},[760,764,769,774,778],{"type":26,"tag":130,"props":761,"children":762},{"style":137},[763],{"type":35,"value":738},{"type":26,"tag":130,"props":765,"children":766},{"style":722},[767],{"type":35,"value":768},"artifactId",{"type":26,"tag":130,"props":770,"children":771},{"style":137},[772],{"type":35,"value":773},">dependency-check-maven\u003C/",{"type":26,"tag":130,"props":775,"children":776},{"style":722},[777],{"type":35,"value":768},{"type":26,"tag":130,"props":779,"children":780},{"style":137},[781],{"type":35,"value":730},{"type":26,"tag":130,"props":783,"children":784},{"class":132,"line":231},[785,789,794,799,803],{"type":26,"tag":130,"props":786,"children":787},{"style":137},[788],{"type":35,"value":738},{"type":26,"tag":130,"props":790,"children":791},{"style":722},[792],{"type":35,"value":793},"version",{"type":26,"tag":130,"props":795,"children":796},{"style":137},[797],{"type":35,"value":798},">9.0.9\u003C/",{"type":26,"tag":130,"props":800,"children":801},{"style":722},[802],{"type":35,"value":793},{"type":26,"tag":130,"props":804,"children":805},{"style":137},[806],{"type":35,"value":730},{"type":26,"tag":130,"props":808,"children":809},{"class":132,"line":364},[810,815,819],{"type":26,"tag":130,"props":811,"children":812},{"style":137},[813],{"type":35,"value":814},"\u003C/",{"type":26,"tag":130,"props":816,"children":817},{"style":722},[818],{"type":35,"value":725},{"type":26,"tag":130,"props":820,"children":821},{"style":137},[822],{"type":35,"value":730},{"type":26,"tag":31,"props":824,"children":825},{},[826],{"type":35,"value":827},"Execute dependency checks regularly in your CI/CD pipeline.",{"type":26,"tag":38,"props":829,"children":831},{"id":830},"_8-logging-and-monitoring",[832],{"type":35,"value":833},"8. Logging and Monitoring",{"type":26,"tag":31,"props":835,"children":836},{},[837],{"type":35,"value":838},"Implement comprehensive logging and monitoring to detect and respond to security incidents:",{"type":26,"tag":121,"props":840,"children":842},{"className":123,"code":841,"language":17,"meta":8,"style":8},"logger.warn(\"Failed login attempt for user: {}\", username);\n",[843],{"type":26,"tag":15,"props":844,"children":845},{"__ignoreMap":8},[846],{"type":26,"tag":130,"props":847,"children":848},{"class":132,"line":133},[849,854,859,863,868],{"type":26,"tag":130,"props":850,"children":851},{"style":137},[852],{"type":35,"value":853},"logger.",{"type":26,"tag":130,"props":855,"children":856},{"style":154},[857],{"type":35,"value":858},"warn",{"type":26,"tag":130,"props":860,"children":861},{"style":137},[862],{"type":35,"value":162},{"type":26,"tag":130,"props":864,"children":865},{"style":165},[866],{"type":35,"value":867},"\"Failed login attempt for user: {}\"",{"type":26,"tag":130,"props":869,"children":870},{"style":137},[871],{"type":35,"value":202},{"type":26,"tag":31,"props":873,"children":874},{},[875],{"type":35,"value":876},"Aggregate logs centrally, and set up alerts for suspicious activities.",{"type":26,"tag":38,"props":878,"children":880},{"id":879},"conclusion",[881],{"type":35,"value":882},"Conclusion",{"type":26,"tag":31,"props":884,"children":885},{},[886],{"type":35,"value":887},"Adopting these best practices can greatly enhance the security posture of your Java applications. Stay proactive by regularly reviewing security measures, updating dependencies, and monitoring your systems. Security is a continuous process, not a one-time setup.",{"type":26,"tag":889,"props":890,"children":892},"h1",{"id":891},"further-reading",[893],{"type":35,"value":894},"Further Reading",{"type":26,"tag":896,"props":897,"children":898},"ul",{},[899,911,921],{"type":26,"tag":54,"props":900,"children":901},{},[902],{"type":26,"tag":903,"props":904,"children":908},"a",{"href":905,"rel":906},"https://owasp.org/www-project-top-ten/",[907],"nofollow",[909],{"type":35,"value":910},"OWASP Top 10",{"type":26,"tag":54,"props":912,"children":913},{},[914],{"type":26,"tag":903,"props":915,"children":918},{"href":916,"rel":917},"https://spring.io/projects/spring-security",[907],[919],{"type":35,"value":920},"Spring Security",{"type":26,"tag":54,"props":922,"children":923},{},[924],{"type":26,"tag":903,"props":925,"children":928},{"href":926,"rel":927},"https://owasp.org/www-project-dependency-check/",[907],[929],{"type":35,"value":930},"OWASP Dependency Check",{"type":26,"tag":932,"props":933,"children":934},"style",{},[935],{"type":35,"value":936},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}",{"title":8,"searchDepth":176,"depth":176,"links":938},[939,940,941,942,943,944,945,946,947,948],{"id":40,"depth":176,"text":43},{"id":111,"depth":176,"text":114},{"id":264,"depth":176,"text":267},{"id":383,"depth":176,"text":386},{"id":522,"depth":176,"text":525},{"id":563,"depth":176,"text":566},{"id":595,"depth":176,"text":598},{"id":694,"depth":176,"text":697},{"id":830,"depth":176,"text":833},{"id":879,"depth":176,"text":882},"markdown","content:posts:java-security-best-practices.md","content","posts/java-security-best-practices.md","posts/java-security-best-practices","md",{"_path":956,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":957,"description":958,"date":959,"layout":12,"subtitle":960,"image":961,"optimized_image":961,"category":15,"tags":962,"author":21,"paginate":7,"body":966,"_type":949,"_id":1775,"_source":951,"_file":1776,"_stem":1777,"_extension":954},"/posts/circuit-breaking-resilience","Circuit Breaking in Distributed Systems","An expert guide to understanding and implementing circuit breakers in distributed systems, with practical Java examples using Resilience4j and best practices.","2024-07-15T11:00:00.000Z","Enhancing Resilience with Circuit Breaker Patterns","/assets/img/uploads/circuit-breaking-resilience.png",[15,17,963,964,965],"resilience","circuit-breaker","distributed-systems",{"type":23,"children":967,"toc":1763},[968,976,982,987,1021,1026,1032,1037,1055,1061,1068,1073,1183,1189,1396,1402,1407,1574,1580,1585,1679,1684,1690,1713,1717,1722,1726,1759],{"type":26,"tag":27,"props":969,"children":970},{},[971],{"type":26,"tag":31,"props":972,"children":973},{},[974],{"type":35,"value":975},"In modern distributed systems, failures are inevitable. The circuit breaker pattern helps maintain system stability by preventing failures from cascading across service boundaries. In this post, we'll dive deep into circuit breakers, explore their importance, and demonstrate practical implementation using Resilience4j in Java.",{"type":26,"tag":38,"props":977,"children":979},{"id":978},"understanding-the-circuit-breaker-pattern",[980],{"type":35,"value":981},"Understanding the Circuit Breaker Pattern",{"type":26,"tag":31,"props":983,"children":984},{},[985],{"type":35,"value":986},"The circuit breaker pattern prevents a service from making repeated calls to an external service that is experiencing issues. It has three main states:",{"type":26,"tag":896,"props":988,"children":989},{},[990,1001,1011],{"type":26,"tag":54,"props":991,"children":992},{},[993,999],{"type":26,"tag":994,"props":995,"children":996},"strong",{},[997],{"type":35,"value":998},"Closed:",{"type":35,"value":1000}," All requests pass through normally.",{"type":26,"tag":54,"props":1002,"children":1003},{},[1004,1009],{"type":26,"tag":994,"props":1005,"children":1006},{},[1007],{"type":35,"value":1008},"Open:",{"type":35,"value":1010}," Requests fail fast, bypassing the problematic service.",{"type":26,"tag":54,"props":1012,"children":1013},{},[1014,1019],{"type":26,"tag":994,"props":1015,"children":1016},{},[1017],{"type":35,"value":1018},"Half-Open:",{"type":35,"value":1020}," A limited number of requests test if the external service has recovered.",{"type":26,"tag":31,"props":1022,"children":1023},{},[1024],{"type":35,"value":1025},"This mechanism helps improve the resilience and responsiveness of your systems.",{"type":26,"tag":38,"props":1027,"children":1029},{"id":1028},"when-to-use-circuit-breakers",[1030],{"type":35,"value":1031},"When to Use Circuit Breakers",{"type":26,"tag":31,"props":1033,"children":1034},{},[1035],{"type":35,"value":1036},"Circuit breakers are essential when:",{"type":26,"tag":896,"props":1038,"children":1039},{},[1040,1045,1050],{"type":26,"tag":54,"props":1041,"children":1042},{},[1043],{"type":35,"value":1044},"Your system relies on remote calls (microservices architecture, external APIs).",{"type":26,"tag":54,"props":1046,"children":1047},{},[1048],{"type":35,"value":1049},"You need to prevent failure propagation.",{"type":26,"tag":54,"props":1051,"children":1052},{},[1053],{"type":35,"value":1054},"You aim to improve user experience by quickly responding to failures.",{"type":26,"tag":38,"props":1056,"children":1058},{"id":1057},"implementing-circuit-breakers-with-resilience4j",[1059],{"type":35,"value":1060},"Implementing Circuit Breakers with Resilience4j",{"type":26,"tag":1062,"props":1063,"children":1065},"h3",{"id":1064},"step-1-adding-dependencies",[1066],{"type":35,"value":1067},"Step 1: Adding Dependencies",{"type":26,"tag":31,"props":1069,"children":1070},{},[1071],{"type":35,"value":1072},"Add Resilience4j dependencies to your project (Maven example):",{"type":26,"tag":121,"props":1074,"children":1076},{"className":705,"code":1075,"language":707,"meta":8,"style":8},"\u003Cdependency>\n    \u003CgroupId>io.github.resilience4j\u003C/groupId>\n    \u003CartifactId>resilience4j-circuitbreaker\u003C/artifactId>\n    \u003Cversion>2.0.2\u003C/version>\n\u003C/dependency>\n",[1077],{"type":26,"tag":15,"props":1078,"children":1079},{"__ignoreMap":8},[1080,1096,1120,1144,1168],{"type":26,"tag":130,"props":1081,"children":1082},{"class":132,"line":133},[1083,1087,1092],{"type":26,"tag":130,"props":1084,"children":1085},{"style":137},[1086],{"type":35,"value":719},{"type":26,"tag":130,"props":1088,"children":1089},{"style":722},[1090],{"type":35,"value":1091},"dependency",{"type":26,"tag":130,"props":1093,"children":1094},{"style":137},[1095],{"type":35,"value":730},{"type":26,"tag":130,"props":1097,"children":1098},{"class":132,"line":176},[1099,1103,1107,1112,1116],{"type":26,"tag":130,"props":1100,"children":1101},{"style":137},[1102],{"type":35,"value":738},{"type":26,"tag":130,"props":1104,"children":1105},{"style":722},[1106],{"type":35,"value":743},{"type":26,"tag":130,"props":1108,"children":1109},{"style":137},[1110],{"type":35,"value":1111},">io.github.resilience4j\u003C/",{"type":26,"tag":130,"props":1113,"children":1114},{"style":722},[1115],{"type":35,"value":743},{"type":26,"tag":130,"props":1117,"children":1118},{"style":137},[1119],{"type":35,"value":730},{"type":26,"tag":130,"props":1121,"children":1122},{"class":132,"line":205},[1123,1127,1131,1136,1140],{"type":26,"tag":130,"props":1124,"children":1125},{"style":137},[1126],{"type":35,"value":738},{"type":26,"tag":130,"props":1128,"children":1129},{"style":722},[1130],{"type":35,"value":768},{"type":26,"tag":130,"props":1132,"children":1133},{"style":137},[1134],{"type":35,"value":1135},">resilience4j-circuitbreaker\u003C/",{"type":26,"tag":130,"props":1137,"children":1138},{"style":722},[1139],{"type":35,"value":768},{"type":26,"tag":130,"props":1141,"children":1142},{"style":137},[1143],{"type":35,"value":730},{"type":26,"tag":130,"props":1145,"children":1146},{"class":132,"line":231},[1147,1151,1155,1160,1164],{"type":26,"tag":130,"props":1148,"children":1149},{"style":137},[1150],{"type":35,"value":738},{"type":26,"tag":130,"props":1152,"children":1153},{"style":722},[1154],{"type":35,"value":793},{"type":26,"tag":130,"props":1156,"children":1157},{"style":137},[1158],{"type":35,"value":1159},">2.0.2\u003C/",{"type":26,"tag":130,"props":1161,"children":1162},{"style":722},[1163],{"type":35,"value":793},{"type":26,"tag":130,"props":1165,"children":1166},{"style":137},[1167],{"type":35,"value":730},{"type":26,"tag":130,"props":1169,"children":1170},{"class":132,"line":364},[1171,1175,1179],{"type":26,"tag":130,"props":1172,"children":1173},{"style":137},[1174],{"type":35,"value":814},{"type":26,"tag":130,"props":1176,"children":1177},{"style":722},[1178],{"type":35,"value":1091},{"type":26,"tag":130,"props":1180,"children":1181},{"style":137},[1182],{"type":35,"value":730},{"type":26,"tag":1062,"props":1184,"children":1186},{"id":1185},"step-2-configuring-circuit-breaker",[1187],{"type":35,"value":1188},"Step 2: Configuring Circuit Breaker",{"type":26,"tag":121,"props":1190,"children":1192},{"className":123,"code":1191,"language":17,"meta":8,"style":8},"CircuitBreakerConfig config = CircuitBreakerConfig.custom()\n    .failureRateThreshold(50)\n    .waitDurationInOpenState(Duration.ofMillis(1000))\n    .permittedNumberOfCallsInHalfOpenState(2)\n    .minimumNumberOfCalls(5)\n    .build();\n\nCircuitBreaker circuitBreaker = CircuitBreaker.of(\"myService\", config);\n",[1193],{"type":26,"tag":15,"props":1194,"children":1195},{"__ignoreMap":8},[1196,1223,1250,1286,1310,1335,1351,1359],{"type":26,"tag":130,"props":1197,"children":1198},{"class":132,"line":133},[1199,1204,1208,1213,1218],{"type":26,"tag":130,"props":1200,"children":1201},{"style":137},[1202],{"type":35,"value":1203},"CircuitBreakerConfig config ",{"type":26,"tag":130,"props":1205,"children":1206},{"style":143},[1207],{"type":35,"value":146},{"type":26,"tag":130,"props":1209,"children":1210},{"style":137},[1211],{"type":35,"value":1212}," CircuitBreakerConfig.",{"type":26,"tag":130,"props":1214,"children":1215},{"style":154},[1216],{"type":35,"value":1217},"custom",{"type":26,"tag":130,"props":1219,"children":1220},{"style":137},[1221],{"type":35,"value":1222},"()\n",{"type":26,"tag":130,"props":1224,"children":1225},{"class":132,"line":176},[1226,1231,1236,1240,1245],{"type":26,"tag":130,"props":1227,"children":1228},{"style":137},[1229],{"type":35,"value":1230},"    .",{"type":26,"tag":130,"props":1232,"children":1233},{"style":154},[1234],{"type":35,"value":1235},"failureRateThreshold",{"type":26,"tag":130,"props":1237,"children":1238},{"style":137},[1239],{"type":35,"value":162},{"type":26,"tag":130,"props":1241,"children":1242},{"style":194},[1243],{"type":35,"value":1244},"50",{"type":26,"tag":130,"props":1246,"children":1247},{"style":137},[1248],{"type":35,"value":1249},")\n",{"type":26,"tag":130,"props":1251,"children":1252},{"class":132,"line":205},[1253,1257,1262,1267,1272,1276,1281],{"type":26,"tag":130,"props":1254,"children":1255},{"style":137},[1256],{"type":35,"value":1230},{"type":26,"tag":130,"props":1258,"children":1259},{"style":154},[1260],{"type":35,"value":1261},"waitDurationInOpenState",{"type":26,"tag":130,"props":1263,"children":1264},{"style":137},[1265],{"type":35,"value":1266},"(Duration.",{"type":26,"tag":130,"props":1268,"children":1269},{"style":154},[1270],{"type":35,"value":1271},"ofMillis",{"type":26,"tag":130,"props":1273,"children":1274},{"style":137},[1275],{"type":35,"value":162},{"type":26,"tag":130,"props":1277,"children":1278},{"style":194},[1279],{"type":35,"value":1280},"1000",{"type":26,"tag":130,"props":1282,"children":1283},{"style":137},[1284],{"type":35,"value":1285},"))\n",{"type":26,"tag":130,"props":1287,"children":1288},{"class":132,"line":231},[1289,1293,1298,1302,1306],{"type":26,"tag":130,"props":1290,"children":1291},{"style":137},[1292],{"type":35,"value":1230},{"type":26,"tag":130,"props":1294,"children":1295},{"style":154},[1296],{"type":35,"value":1297},"permittedNumberOfCallsInHalfOpenState",{"type":26,"tag":130,"props":1299,"children":1300},{"style":137},[1301],{"type":35,"value":162},{"type":26,"tag":130,"props":1303,"children":1304},{"style":194},[1305],{"type":35,"value":223},{"type":26,"tag":130,"props":1307,"children":1308},{"style":137},[1309],{"type":35,"value":1249},{"type":26,"tag":130,"props":1311,"children":1312},{"class":132,"line":364},[1313,1317,1322,1326,1331],{"type":26,"tag":130,"props":1314,"children":1315},{"style":137},[1316],{"type":35,"value":1230},{"type":26,"tag":130,"props":1318,"children":1319},{"style":154},[1320],{"type":35,"value":1321},"minimumNumberOfCalls",{"type":26,"tag":130,"props":1323,"children":1324},{"style":137},[1325],{"type":35,"value":162},{"type":26,"tag":130,"props":1327,"children":1328},{"style":194},[1329],{"type":35,"value":1330},"5",{"type":26,"tag":130,"props":1332,"children":1333},{"style":137},[1334],{"type":35,"value":1249},{"type":26,"tag":130,"props":1336,"children":1337},{"class":132,"line":374},[1338,1342,1347],{"type":26,"tag":130,"props":1339,"children":1340},{"style":137},[1341],{"type":35,"value":1230},{"type":26,"tag":130,"props":1343,"children":1344},{"style":154},[1345],{"type":35,"value":1346},"build",{"type":26,"tag":130,"props":1348,"children":1349},{"style":137},[1350],{"type":35,"value":256},{"type":26,"tag":130,"props":1352,"children":1354},{"class":132,"line":1353},7,[1355],{"type":26,"tag":130,"props":1356,"children":1357},{"emptyLinePlaceholder":298},[1358],{"type":35,"value":301},{"type":26,"tag":130,"props":1360,"children":1362},{"class":132,"line":1361},8,[1363,1368,1372,1377,1382,1386,1391],{"type":26,"tag":130,"props":1364,"children":1365},{"style":137},[1366],{"type":35,"value":1367},"CircuitBreaker circuitBreaker ",{"type":26,"tag":130,"props":1369,"children":1370},{"style":143},[1371],{"type":35,"value":146},{"type":26,"tag":130,"props":1373,"children":1374},{"style":137},[1375],{"type":35,"value":1376}," CircuitBreaker.",{"type":26,"tag":130,"props":1378,"children":1379},{"style":154},[1380],{"type":35,"value":1381},"of",{"type":26,"tag":130,"props":1383,"children":1384},{"style":137},[1385],{"type":35,"value":162},{"type":26,"tag":130,"props":1387,"children":1388},{"style":165},[1389],{"type":35,"value":1390},"\"myService\"",{"type":26,"tag":130,"props":1392,"children":1393},{"style":137},[1394],{"type":35,"value":1395},", config);\n",{"type":26,"tag":1062,"props":1397,"children":1399},{"id":1398},"step-3-using-circuit-breaker",[1400],{"type":35,"value":1401},"Step 3: Using Circuit Breaker",{"type":26,"tag":31,"props":1403,"children":1404},{},[1405],{"type":35,"value":1406},"Wrap service calls using the circuit breaker:",{"type":26,"tag":121,"props":1408,"children":1410},{"className":123,"code":1409,"language":17,"meta":8,"style":8},"Supplier\u003CString> decoratedSupplier = CircuitBreaker.decorateSupplier(circuitBreaker, () -> myService.remoteCall());\n\nTry.ofSupplier(decoratedSupplier)\n    .recover(throwable -> \"Fallback response\")\n    .onSuccess(result -> System.out.println(\"Response: \" + result));\n",[1411],{"type":26,"tag":15,"props":1412,"children":1413},{"__ignoreMap":8},[1414,1469,1476,1494,1524],{"type":26,"tag":130,"props":1415,"children":1416},{"class":132,"line":133},[1417,1422,1427,1432,1436,1440,1445,1450,1455,1460,1465],{"type":26,"tag":130,"props":1418,"children":1419},{"style":137},[1420],{"type":35,"value":1421},"Supplier\u003C",{"type":26,"tag":130,"props":1423,"children":1424},{"style":143},[1425],{"type":35,"value":1426},"String",{"type":26,"tag":130,"props":1428,"children":1429},{"style":137},[1430],{"type":35,"value":1431},"> decoratedSupplier ",{"type":26,"tag":130,"props":1433,"children":1434},{"style":143},[1435],{"type":35,"value":146},{"type":26,"tag":130,"props":1437,"children":1438},{"style":137},[1439],{"type":35,"value":1376},{"type":26,"tag":130,"props":1441,"children":1442},{"style":154},[1443],{"type":35,"value":1444},"decorateSupplier",{"type":26,"tag":130,"props":1446,"children":1447},{"style":137},[1448],{"type":35,"value":1449},"(circuitBreaker, () ",{"type":26,"tag":130,"props":1451,"children":1452},{"style":143},[1453],{"type":35,"value":1454},"->",{"type":26,"tag":130,"props":1456,"children":1457},{"style":137},[1458],{"type":35,"value":1459}," myService.",{"type":26,"tag":130,"props":1461,"children":1462},{"style":154},[1463],{"type":35,"value":1464},"remoteCall",{"type":26,"tag":130,"props":1466,"children":1467},{"style":137},[1468],{"type":35,"value":338},{"type":26,"tag":130,"props":1470,"children":1471},{"class":132,"line":176},[1472],{"type":26,"tag":130,"props":1473,"children":1474},{"emptyLinePlaceholder":298},[1475],{"type":35,"value":301},{"type":26,"tag":130,"props":1477,"children":1478},{"class":132,"line":205},[1479,1484,1489],{"type":26,"tag":130,"props":1480,"children":1481},{"style":137},[1482],{"type":35,"value":1483},"Try.",{"type":26,"tag":130,"props":1485,"children":1486},{"style":154},[1487],{"type":35,"value":1488},"ofSupplier",{"type":26,"tag":130,"props":1490,"children":1491},{"style":137},[1492],{"type":35,"value":1493},"(decoratedSupplier)\n",{"type":26,"tag":130,"props":1495,"children":1496},{"class":132,"line":231},[1497,1501,1506,1511,1515,1520],{"type":26,"tag":130,"props":1498,"children":1499},{"style":137},[1500],{"type":35,"value":1230},{"type":26,"tag":130,"props":1502,"children":1503},{"style":154},[1504],{"type":35,"value":1505},"recover",{"type":26,"tag":130,"props":1507,"children":1508},{"style":137},[1509],{"type":35,"value":1510},"(throwable ",{"type":26,"tag":130,"props":1512,"children":1513},{"style":143},[1514],{"type":35,"value":1454},{"type":26,"tag":130,"props":1516,"children":1517},{"style":165},[1518],{"type":35,"value":1519}," \"Fallback response\"",{"type":26,"tag":130,"props":1521,"children":1522},{"style":137},[1523],{"type":35,"value":1249},{"type":26,"tag":130,"props":1525,"children":1526},{"class":132,"line":364},[1527,1531,1536,1541,1545,1550,1555,1559,1564,1569],{"type":26,"tag":130,"props":1528,"children":1529},{"style":137},[1530],{"type":35,"value":1230},{"type":26,"tag":130,"props":1532,"children":1533},{"style":154},[1534],{"type":35,"value":1535},"onSuccess",{"type":26,"tag":130,"props":1537,"children":1538},{"style":137},[1539],{"type":35,"value":1540},"(result ",{"type":26,"tag":130,"props":1542,"children":1543},{"style":143},[1544],{"type":35,"value":1454},{"type":26,"tag":130,"props":1546,"children":1547},{"style":137},[1548],{"type":35,"value":1549}," System.out.",{"type":26,"tag":130,"props":1551,"children":1552},{"style":154},[1553],{"type":35,"value":1554},"println",{"type":26,"tag":130,"props":1556,"children":1557},{"style":137},[1558],{"type":35,"value":162},{"type":26,"tag":130,"props":1560,"children":1561},{"style":165},[1562],{"type":35,"value":1563},"\"Response: \"",{"type":26,"tag":130,"props":1565,"children":1566},{"style":143},[1567],{"type":35,"value":1568}," +",{"type":26,"tag":130,"props":1570,"children":1571},{"style":137},[1572],{"type":35,"value":1573}," result));\n",{"type":26,"tag":38,"props":1575,"children":1577},{"id":1576},"monitoring-and-metrics",[1578],{"type":35,"value":1579},"Monitoring and Metrics",{"type":26,"tag":31,"props":1581,"children":1582},{},[1583],{"type":35,"value":1584},"Resilience4j provides built-in support for metrics and monitoring:",{"type":26,"tag":121,"props":1586,"children":1588},{"className":123,"code":1587,"language":17,"meta":8,"style":8},"CircuitBreakerRegistry registry = CircuitBreakerRegistry.ofDefaults();\nregistry.getEventPublisher()\n    .onStateTransition(event -> System.out.println(event.getStateTransition()));\n",[1589],{"type":26,"tag":15,"props":1590,"children":1591},{"__ignoreMap":8},[1592,1618,1635],{"type":26,"tag":130,"props":1593,"children":1594},{"class":132,"line":133},[1595,1600,1604,1609,1614],{"type":26,"tag":130,"props":1596,"children":1597},{"style":137},[1598],{"type":35,"value":1599},"CircuitBreakerRegistry registry ",{"type":26,"tag":130,"props":1601,"children":1602},{"style":143},[1603],{"type":35,"value":146},{"type":26,"tag":130,"props":1605,"children":1606},{"style":137},[1607],{"type":35,"value":1608}," CircuitBreakerRegistry.",{"type":26,"tag":130,"props":1610,"children":1611},{"style":154},[1612],{"type":35,"value":1613},"ofDefaults",{"type":26,"tag":130,"props":1615,"children":1616},{"style":137},[1617],{"type":35,"value":256},{"type":26,"tag":130,"props":1619,"children":1620},{"class":132,"line":176},[1621,1626,1631],{"type":26,"tag":130,"props":1622,"children":1623},{"style":137},[1624],{"type":35,"value":1625},"registry.",{"type":26,"tag":130,"props":1627,"children":1628},{"style":154},[1629],{"type":35,"value":1630},"getEventPublisher",{"type":26,"tag":130,"props":1632,"children":1633},{"style":137},[1634],{"type":35,"value":1222},{"type":26,"tag":130,"props":1636,"children":1637},{"class":132,"line":205},[1638,1642,1647,1652,1656,1660,1664,1669,1674],{"type":26,"tag":130,"props":1639,"children":1640},{"style":137},[1641],{"type":35,"value":1230},{"type":26,"tag":130,"props":1643,"children":1644},{"style":154},[1645],{"type":35,"value":1646},"onStateTransition",{"type":26,"tag":130,"props":1648,"children":1649},{"style":137},[1650],{"type":35,"value":1651},"(event ",{"type":26,"tag":130,"props":1653,"children":1654},{"style":143},[1655],{"type":35,"value":1454},{"type":26,"tag":130,"props":1657,"children":1658},{"style":137},[1659],{"type":35,"value":1549},{"type":26,"tag":130,"props":1661,"children":1662},{"style":154},[1663],{"type":35,"value":1554},{"type":26,"tag":130,"props":1665,"children":1666},{"style":137},[1667],{"type":35,"value":1668},"(event.",{"type":26,"tag":130,"props":1670,"children":1671},{"style":154},[1672],{"type":35,"value":1673},"getStateTransition",{"type":26,"tag":130,"props":1675,"children":1676},{"style":137},[1677],{"type":35,"value":1678},"()));\n",{"type":26,"tag":31,"props":1680,"children":1681},{},[1682],{"type":35,"value":1683},"Integrate with Prometheus, Grafana, or other observability tools for comprehensive monitoring.",{"type":26,"tag":38,"props":1685,"children":1687},{"id":1686},"best-practices-for-circuit-breaking",[1688],{"type":35,"value":1689},"Best Practices for Circuit Breaking",{"type":26,"tag":896,"props":1691,"children":1692},{},[1693,1698,1703,1708],{"type":26,"tag":54,"props":1694,"children":1695},{},[1696],{"type":35,"value":1697},"Configure sensible thresholds to avoid premature circuit opening.",{"type":26,"tag":54,"props":1699,"children":1700},{},[1701],{"type":35,"value":1702},"Always define fallback mechanisms.",{"type":26,"tag":54,"props":1704,"children":1705},{},[1706],{"type":35,"value":1707},"Regularly monitor circuit breaker states and metrics.",{"type":26,"tag":54,"props":1709,"children":1710},{},[1711],{"type":35,"value":1712},"Test thoroughly to ensure reliability under failure conditions.",{"type":26,"tag":38,"props":1714,"children":1715},{"id":879},[1716],{"type":35,"value":882},{"type":26,"tag":31,"props":1718,"children":1719},{},[1720],{"type":35,"value":1721},"Implementing circuit breakers using Resilience4j significantly enhances the resilience of your Java-based distributed systems. This proactive approach ensures your systems gracefully handle failures, maintaining service availability and user satisfaction.",{"type":26,"tag":889,"props":1723,"children":1724},{"id":891},[1725],{"type":35,"value":894},{"type":26,"tag":896,"props":1727,"children":1728},{},[1729,1739,1749],{"type":26,"tag":54,"props":1730,"children":1731},{},[1732],{"type":26,"tag":903,"props":1733,"children":1736},{"href":1734,"rel":1735},"https://resilience4j.readme.io/docs",[907],[1737],{"type":35,"value":1738},"Resilience4j Official Documentation",{"type":26,"tag":54,"props":1740,"children":1741},{},[1742],{"type":26,"tag":903,"props":1743,"children":1746},{"href":1744,"rel":1745},"https://martinfowler.com/bliki/CircuitBreaker.html",[907],[1747],{"type":35,"value":1748},"Circuit Breaker Pattern by Martin Fowler",{"type":26,"tag":54,"props":1750,"children":1751},{},[1752],{"type":26,"tag":903,"props":1753,"children":1756},{"href":1754,"rel":1755},"https://microservices.io/patterns/reliability/circuit-breaker.html",[907],[1757],{"type":35,"value":1758},"Microservices Patterns by Chris Richardson",{"type":26,"tag":932,"props":1760,"children":1761},{},[1762],{"type":35,"value":936},{"title":8,"searchDepth":176,"depth":176,"links":1764},[1765,1766,1767,1772,1773,1774],{"id":978,"depth":176,"text":981},{"id":1028,"depth":176,"text":1031},{"id":1057,"depth":176,"text":1060,"children":1768},[1769,1770,1771],{"id":1064,"depth":205,"text":1067},{"id":1185,"depth":205,"text":1188},{"id":1398,"depth":205,"text":1401},{"id":1576,"depth":176,"text":1579},{"id":1686,"depth":176,"text":1689},{"id":879,"depth":176,"text":882},"content:posts:circuit-breaking-resilience.md","posts/circuit-breaking-resilience.md","posts/circuit-breaking-resilience",{"_path":1779,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":1780,"description":1781,"date":1782,"layout":12,"subtitle":1783,"image":1784,"optimized_image":1784,"category":15,"tags":1785,"author":21,"paginate":7,"body":1789,"_type":949,"_id":2799,"_source":951,"_file":2800,"_stem":2801,"_extension":954},"/posts/maven-and-github-actions","Automating Java Builds with Maven and GitHub Actions CI/CD","Learn how to set up automated Java build pipelines using Maven and GitHub Actions, including practical examples and detailed instructions.","2024-06-15T11:00:00.000Z","A Step-by-Step Guide to Continuous Integration and Deployment","/assets/img/uploads/java-maven-github-actions.png",[15,17,1786,1787,1788],"maven","github-actions","cicd",{"type":23,"children":1790,"toc":2788},[1791,1813,1819,1840,1846,1851,1859,1872,2215,2221,2280,2286,2291,2451,2457,2462,2534,2546,2552,2557,2618,2630,2636,2659,2665,2670,2725,2738,2742,2747,2751,2784],{"type":26,"tag":27,"props":1792,"children":1793},{},[1794],{"type":26,"tag":31,"props":1795,"children":1796},{},[1797,1799,1804,1806,1811],{"type":35,"value":1798},"Continuous Integration and Continuous Deployment (CI/CD) streamline development workflows, improve software quality, and accelerate delivery. This tutorial guides you through setting up automated Java builds using ",{"type":26,"tag":994,"props":1800,"children":1801},{},[1802],{"type":35,"value":1803},"Maven",{"type":35,"value":1805}," and ",{"type":26,"tag":994,"props":1807,"children":1808},{},[1809],{"type":35,"value":1810},"GitHub Actions",{"type":35,"value":1812},".",{"type":26,"tag":38,"props":1814,"children":1816},{"id":1815},"prerequisites",[1817],{"type":35,"value":1818},"Prerequisites",{"type":26,"tag":896,"props":1820,"children":1821},{},[1822,1835],{"type":26,"tag":54,"props":1823,"children":1824},{},[1825,1827,1833],{"type":35,"value":1826},"A Java project with Maven configured (",{"type":26,"tag":15,"props":1828,"children":1830},{"className":1829},[],[1831],{"type":35,"value":1832},"pom.xml",{"type":35,"value":1834},").",{"type":26,"tag":54,"props":1836,"children":1837},{},[1838],{"type":35,"value":1839},"GitHub repository.",{"type":26,"tag":38,"props":1841,"children":1843},{"id":1842},"step-1-setting-up-your-github-actions-workflow",[1844],{"type":35,"value":1845},"Step 1: Setting Up Your GitHub Actions Workflow",{"type":26,"tag":31,"props":1847,"children":1848},{},[1849],{"type":35,"value":1850},"In your repository, create the following directory structure:",{"type":26,"tag":121,"props":1852,"children":1854},{"code":1853},".github/workflows/\n",[1855],{"type":26,"tag":15,"props":1856,"children":1857},{"__ignoreMap":8},[1858],{"type":35,"value":1853},{"type":26,"tag":31,"props":1860,"children":1861},{},[1862,1864,1870],{"type":35,"value":1863},"Create a new file named ",{"type":26,"tag":15,"props":1865,"children":1867},{"className":1866},[],[1868],{"type":35,"value":1869},"maven-ci.yml",{"type":35,"value":1871}," within this directory:",{"type":26,"tag":121,"props":1873,"children":1877},{"code":1874,"language":1875,"meta":8,"className":1876,"style":8},"name: Maven CI\n\non:\n  push:\n    branches: [ \"main\" ]\n  pull_request:\n    branches: [ \"main\" ]\n\njobs:\n  build:\n    runs-on: ubuntu-latest\n\n    steps:\n      - uses: actions/checkout@v4\n      - name: Set up JDK 21\n        uses: actions/setup-java@v4\n        with:\n          java-version: '21'\n          distribution: 'temurin'\n\n      - name: Build with Maven\n        run: mvn clean install\n","yml","language-yml shiki shiki-themes github-dark github-light",[1878],{"type":26,"tag":15,"props":1879,"children":1880},{"__ignoreMap":8},[1881,1899,1906,1919,1931,1954,1966,1985,1992,2005,2018,2036,2044,2057,2080,2101,2119,2132,2150,2168,2176,2197],{"type":26,"tag":130,"props":1882,"children":1883},{"class":132,"line":133},[1884,1889,1894],{"type":26,"tag":130,"props":1885,"children":1886},{"style":722},[1887],{"type":35,"value":1888},"name",{"type":26,"tag":130,"props":1890,"children":1891},{"style":137},[1892],{"type":35,"value":1893},": ",{"type":26,"tag":130,"props":1895,"children":1896},{"style":165},[1897],{"type":35,"value":1898},"Maven CI\n",{"type":26,"tag":130,"props":1900,"children":1901},{"class":132,"line":176},[1902],{"type":26,"tag":130,"props":1903,"children":1904},{"emptyLinePlaceholder":298},[1905],{"type":35,"value":301},{"type":26,"tag":130,"props":1907,"children":1908},{"class":132,"line":205},[1909,1914],{"type":26,"tag":130,"props":1910,"children":1911},{"style":194},[1912],{"type":35,"value":1913},"on",{"type":26,"tag":130,"props":1915,"children":1916},{"style":137},[1917],{"type":35,"value":1918},":\n",{"type":26,"tag":130,"props":1920,"children":1921},{"class":132,"line":231},[1922,1927],{"type":26,"tag":130,"props":1923,"children":1924},{"style":722},[1925],{"type":35,"value":1926},"  push",{"type":26,"tag":130,"props":1928,"children":1929},{"style":137},[1930],{"type":35,"value":1918},{"type":26,"tag":130,"props":1932,"children":1933},{"class":132,"line":364},[1934,1939,1944,1949],{"type":26,"tag":130,"props":1935,"children":1936},{"style":722},[1937],{"type":35,"value":1938},"    branches",{"type":26,"tag":130,"props":1940,"children":1941},{"style":137},[1942],{"type":35,"value":1943},": [ ",{"type":26,"tag":130,"props":1945,"children":1946},{"style":165},[1947],{"type":35,"value":1948},"\"main\"",{"type":26,"tag":130,"props":1950,"children":1951},{"style":137},[1952],{"type":35,"value":1953}," ]\n",{"type":26,"tag":130,"props":1955,"children":1956},{"class":132,"line":374},[1957,1962],{"type":26,"tag":130,"props":1958,"children":1959},{"style":722},[1960],{"type":35,"value":1961},"  pull_request",{"type":26,"tag":130,"props":1963,"children":1964},{"style":137},[1965],{"type":35,"value":1918},{"type":26,"tag":130,"props":1967,"children":1968},{"class":132,"line":1353},[1969,1973,1977,1981],{"type":26,"tag":130,"props":1970,"children":1971},{"style":722},[1972],{"type":35,"value":1938},{"type":26,"tag":130,"props":1974,"children":1975},{"style":137},[1976],{"type":35,"value":1943},{"type":26,"tag":130,"props":1978,"children":1979},{"style":165},[1980],{"type":35,"value":1948},{"type":26,"tag":130,"props":1982,"children":1983},{"style":137},[1984],{"type":35,"value":1953},{"type":26,"tag":130,"props":1986,"children":1987},{"class":132,"line":1361},[1988],{"type":26,"tag":130,"props":1989,"children":1990},{"emptyLinePlaceholder":298},[1991],{"type":35,"value":301},{"type":26,"tag":130,"props":1993,"children":1995},{"class":132,"line":1994},9,[1996,2001],{"type":26,"tag":130,"props":1997,"children":1998},{"style":722},[1999],{"type":35,"value":2000},"jobs",{"type":26,"tag":130,"props":2002,"children":2003},{"style":137},[2004],{"type":35,"value":1918},{"type":26,"tag":130,"props":2006,"children":2008},{"class":132,"line":2007},10,[2009,2014],{"type":26,"tag":130,"props":2010,"children":2011},{"style":722},[2012],{"type":35,"value":2013},"  build",{"type":26,"tag":130,"props":2015,"children":2016},{"style":137},[2017],{"type":35,"value":1918},{"type":26,"tag":130,"props":2019,"children":2021},{"class":132,"line":2020},11,[2022,2027,2031],{"type":26,"tag":130,"props":2023,"children":2024},{"style":722},[2025],{"type":35,"value":2026},"    runs-on",{"type":26,"tag":130,"props":2028,"children":2029},{"style":137},[2030],{"type":35,"value":1893},{"type":26,"tag":130,"props":2032,"children":2033},{"style":165},[2034],{"type":35,"value":2035},"ubuntu-latest\n",{"type":26,"tag":130,"props":2037,"children":2039},{"class":132,"line":2038},12,[2040],{"type":26,"tag":130,"props":2041,"children":2042},{"emptyLinePlaceholder":298},[2043],{"type":35,"value":301},{"type":26,"tag":130,"props":2045,"children":2047},{"class":132,"line":2046},13,[2048,2053],{"type":26,"tag":130,"props":2049,"children":2050},{"style":722},[2051],{"type":35,"value":2052},"    steps",{"type":26,"tag":130,"props":2054,"children":2055},{"style":137},[2056],{"type":35,"value":1918},{"type":26,"tag":130,"props":2058,"children":2060},{"class":132,"line":2059},14,[2061,2066,2071,2075],{"type":26,"tag":130,"props":2062,"children":2063},{"style":137},[2064],{"type":35,"value":2065},"      - ",{"type":26,"tag":130,"props":2067,"children":2068},{"style":722},[2069],{"type":35,"value":2070},"uses",{"type":26,"tag":130,"props":2072,"children":2073},{"style":137},[2074],{"type":35,"value":1893},{"type":26,"tag":130,"props":2076,"children":2077},{"style":165},[2078],{"type":35,"value":2079},"actions/checkout@v4\n",{"type":26,"tag":130,"props":2081,"children":2083},{"class":132,"line":2082},15,[2084,2088,2092,2096],{"type":26,"tag":130,"props":2085,"children":2086},{"style":137},[2087],{"type":35,"value":2065},{"type":26,"tag":130,"props":2089,"children":2090},{"style":722},[2091],{"type":35,"value":1888},{"type":26,"tag":130,"props":2093,"children":2094},{"style":137},[2095],{"type":35,"value":1893},{"type":26,"tag":130,"props":2097,"children":2098},{"style":165},[2099],{"type":35,"value":2100},"Set up JDK 21\n",{"type":26,"tag":130,"props":2102,"children":2104},{"class":132,"line":2103},16,[2105,2110,2114],{"type":26,"tag":130,"props":2106,"children":2107},{"style":722},[2108],{"type":35,"value":2109},"        uses",{"type":26,"tag":130,"props":2111,"children":2112},{"style":137},[2113],{"type":35,"value":1893},{"type":26,"tag":130,"props":2115,"children":2116},{"style":165},[2117],{"type":35,"value":2118},"actions/setup-java@v4\n",{"type":26,"tag":130,"props":2120,"children":2122},{"class":132,"line":2121},17,[2123,2128],{"type":26,"tag":130,"props":2124,"children":2125},{"style":722},[2126],{"type":35,"value":2127},"        with",{"type":26,"tag":130,"props":2129,"children":2130},{"style":137},[2131],{"type":35,"value":1918},{"type":26,"tag":130,"props":2133,"children":2135},{"class":132,"line":2134},18,[2136,2141,2145],{"type":26,"tag":130,"props":2137,"children":2138},{"style":722},[2139],{"type":35,"value":2140},"          java-version",{"type":26,"tag":130,"props":2142,"children":2143},{"style":137},[2144],{"type":35,"value":1893},{"type":26,"tag":130,"props":2146,"children":2147},{"style":165},[2148],{"type":35,"value":2149},"'21'\n",{"type":26,"tag":130,"props":2151,"children":2153},{"class":132,"line":2152},19,[2154,2159,2163],{"type":26,"tag":130,"props":2155,"children":2156},{"style":722},[2157],{"type":35,"value":2158},"          distribution",{"type":26,"tag":130,"props":2160,"children":2161},{"style":137},[2162],{"type":35,"value":1893},{"type":26,"tag":130,"props":2164,"children":2165},{"style":165},[2166],{"type":35,"value":2167},"'temurin'\n",{"type":26,"tag":130,"props":2169,"children":2171},{"class":132,"line":2170},20,[2172],{"type":26,"tag":130,"props":2173,"children":2174},{"emptyLinePlaceholder":298},[2175],{"type":35,"value":301},{"type":26,"tag":130,"props":2177,"children":2179},{"class":132,"line":2178},21,[2180,2184,2188,2192],{"type":26,"tag":130,"props":2181,"children":2182},{"style":137},[2183],{"type":35,"value":2065},{"type":26,"tag":130,"props":2185,"children":2186},{"style":722},[2187],{"type":35,"value":1888},{"type":26,"tag":130,"props":2189,"children":2190},{"style":137},[2191],{"type":35,"value":1893},{"type":26,"tag":130,"props":2193,"children":2194},{"style":165},[2195],{"type":35,"value":2196},"Build with Maven\n",{"type":26,"tag":130,"props":2198,"children":2200},{"class":132,"line":2199},22,[2201,2206,2210],{"type":26,"tag":130,"props":2202,"children":2203},{"style":722},[2204],{"type":35,"value":2205},"        run",{"type":26,"tag":130,"props":2207,"children":2208},{"style":137},[2209],{"type":35,"value":1893},{"type":26,"tag":130,"props":2211,"children":2212},{"style":165},[2213],{"type":35,"value":2214},"mvn clean install\n",{"type":26,"tag":38,"props":2216,"children":2218},{"id":2217},"step-2-understanding-the-workflow",[2219],{"type":35,"value":2220},"Step 2: Understanding the Workflow",{"type":26,"tag":896,"props":2222,"children":2223},{},[2224,2242,2252,2262],{"type":26,"tag":54,"props":2225,"children":2226},{},[2227,2232,2234,2240],{"type":26,"tag":994,"props":2228,"children":2229},{},[2230],{"type":35,"value":2231},"Trigger:",{"type":35,"value":2233}," Activated on push or pull request to the ",{"type":26,"tag":15,"props":2235,"children":2237},{"className":2236},[],[2238],{"type":35,"value":2239},"main",{"type":35,"value":2241}," branch.",{"type":26,"tag":54,"props":2243,"children":2244},{},[2245,2250],{"type":26,"tag":994,"props":2246,"children":2247},{},[2248],{"type":35,"value":2249},"Checkout:",{"type":35,"value":2251}," Retrieves the source code from your repository.",{"type":26,"tag":54,"props":2253,"children":2254},{},[2255,2260],{"type":26,"tag":994,"props":2256,"children":2257},{},[2258],{"type":35,"value":2259},"JDK Setup:",{"type":35,"value":2261}," Installs Java 21 from Temurin.",{"type":26,"tag":54,"props":2263,"children":2264},{},[2265,2270,2272,2278],{"type":26,"tag":994,"props":2266,"children":2267},{},[2268],{"type":35,"value":2269},"Maven Build:",{"type":35,"value":2271}," Executes Maven goals (",{"type":26,"tag":15,"props":2273,"children":2275},{"className":2274},[],[2276],{"type":35,"value":2277},"clean install",{"type":35,"value":2279},") to compile, test, and package your Java application.",{"type":26,"tag":38,"props":2281,"children":2283},{"id":2282},"step-3-add-maven-test-reports",[2284],{"type":35,"value":2285},"Step 3: Add Maven Test Reports",{"type":26,"tag":31,"props":2287,"children":2288},{},[2289],{"type":35,"value":2290},"Enhance your workflow by generating and uploading test reports:",{"type":26,"tag":121,"props":2292,"children":2294},{"code":2293,"language":1875,"meta":8,"className":1876,"style":8},"- name: Run tests and upload reports\n  run: |\n    mvn test\n  continue-on-error: true\n\n- name: Upload test report\n  uses: actions/upload-artifact@v4\n  with:\n    name: test-report\n    path: target/surefire-reports/\n",[2295],{"type":26,"tag":15,"props":2296,"children":2297},{"__ignoreMap":8},[2298,2319,2336,2344,2361,2368,2388,2405,2417,2434],{"type":26,"tag":130,"props":2299,"children":2300},{"class":132,"line":133},[2301,2306,2310,2314],{"type":26,"tag":130,"props":2302,"children":2303},{"style":137},[2304],{"type":35,"value":2305},"- ",{"type":26,"tag":130,"props":2307,"children":2308},{"style":722},[2309],{"type":35,"value":1888},{"type":26,"tag":130,"props":2311,"children":2312},{"style":137},[2313],{"type":35,"value":1893},{"type":26,"tag":130,"props":2315,"children":2316},{"style":165},[2317],{"type":35,"value":2318},"Run tests and upload reports\n",{"type":26,"tag":130,"props":2320,"children":2321},{"class":132,"line":176},[2322,2327,2331],{"type":26,"tag":130,"props":2323,"children":2324},{"style":722},[2325],{"type":35,"value":2326},"  run",{"type":26,"tag":130,"props":2328,"children":2329},{"style":137},[2330],{"type":35,"value":1893},{"type":26,"tag":130,"props":2332,"children":2333},{"style":143},[2334],{"type":35,"value":2335},"|\n",{"type":26,"tag":130,"props":2337,"children":2338},{"class":132,"line":205},[2339],{"type":26,"tag":130,"props":2340,"children":2341},{"style":165},[2342],{"type":35,"value":2343},"    mvn test\n",{"type":26,"tag":130,"props":2345,"children":2346},{"class":132,"line":231},[2347,2352,2356],{"type":26,"tag":130,"props":2348,"children":2349},{"style":722},[2350],{"type":35,"value":2351},"  continue-on-error",{"type":26,"tag":130,"props":2353,"children":2354},{"style":137},[2355],{"type":35,"value":1893},{"type":26,"tag":130,"props":2357,"children":2358},{"style":194},[2359],{"type":35,"value":2360},"true\n",{"type":26,"tag":130,"props":2362,"children":2363},{"class":132,"line":364},[2364],{"type":26,"tag":130,"props":2365,"children":2366},{"emptyLinePlaceholder":298},[2367],{"type":35,"value":301},{"type":26,"tag":130,"props":2369,"children":2370},{"class":132,"line":374},[2371,2375,2379,2383],{"type":26,"tag":130,"props":2372,"children":2373},{"style":137},[2374],{"type":35,"value":2305},{"type":26,"tag":130,"props":2376,"children":2377},{"style":722},[2378],{"type":35,"value":1888},{"type":26,"tag":130,"props":2380,"children":2381},{"style":137},[2382],{"type":35,"value":1893},{"type":26,"tag":130,"props":2384,"children":2385},{"style":165},[2386],{"type":35,"value":2387},"Upload test report\n",{"type":26,"tag":130,"props":2389,"children":2390},{"class":132,"line":1353},[2391,2396,2400],{"type":26,"tag":130,"props":2392,"children":2393},{"style":722},[2394],{"type":35,"value":2395},"  uses",{"type":26,"tag":130,"props":2397,"children":2398},{"style":137},[2399],{"type":35,"value":1893},{"type":26,"tag":130,"props":2401,"children":2402},{"style":165},[2403],{"type":35,"value":2404},"actions/upload-artifact@v4\n",{"type":26,"tag":130,"props":2406,"children":2407},{"class":132,"line":1361},[2408,2413],{"type":26,"tag":130,"props":2409,"children":2410},{"style":722},[2411],{"type":35,"value":2412},"  with",{"type":26,"tag":130,"props":2414,"children":2415},{"style":137},[2416],{"type":35,"value":1918},{"type":26,"tag":130,"props":2418,"children":2419},{"class":132,"line":1994},[2420,2425,2429],{"type":26,"tag":130,"props":2421,"children":2422},{"style":722},[2423],{"type":35,"value":2424},"    name",{"type":26,"tag":130,"props":2426,"children":2427},{"style":137},[2428],{"type":35,"value":1893},{"type":26,"tag":130,"props":2430,"children":2431},{"style":165},[2432],{"type":35,"value":2433},"test-report\n",{"type":26,"tag":130,"props":2435,"children":2436},{"class":132,"line":2007},[2437,2442,2446],{"type":26,"tag":130,"props":2438,"children":2439},{"style":722},[2440],{"type":35,"value":2441},"    path",{"type":26,"tag":130,"props":2443,"children":2444},{"style":137},[2445],{"type":35,"value":1893},{"type":26,"tag":130,"props":2447,"children":2448},{"style":165},[2449],{"type":35,"value":2450},"target/surefire-reports/\n",{"type":26,"tag":38,"props":2452,"children":2454},{"id":2453},"step-4-deploy-artifacts-optional",[2455],{"type":35,"value":2456},"Step 4: Deploy Artifacts (Optional)",{"type":26,"tag":31,"props":2458,"children":2459},{},[2460],{"type":35,"value":2461},"To automatically deploy artifacts, include the deployment steps:",{"type":26,"tag":121,"props":2463,"children":2465},{"code":2464,"language":1875,"meta":8,"className":1876,"style":8},"- name: Deploy package\n  env:\n    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}\n  run: mvn deploy\n",[2466],{"type":26,"tag":15,"props":2467,"children":2468},{"__ignoreMap":8},[2469,2489,2501,2518],{"type":26,"tag":130,"props":2470,"children":2471},{"class":132,"line":133},[2472,2476,2480,2484],{"type":26,"tag":130,"props":2473,"children":2474},{"style":137},[2475],{"type":35,"value":2305},{"type":26,"tag":130,"props":2477,"children":2478},{"style":722},[2479],{"type":35,"value":1888},{"type":26,"tag":130,"props":2481,"children":2482},{"style":137},[2483],{"type":35,"value":1893},{"type":26,"tag":130,"props":2485,"children":2486},{"style":165},[2487],{"type":35,"value":2488},"Deploy package\n",{"type":26,"tag":130,"props":2490,"children":2491},{"class":132,"line":176},[2492,2497],{"type":26,"tag":130,"props":2493,"children":2494},{"style":722},[2495],{"type":35,"value":2496},"  env",{"type":26,"tag":130,"props":2498,"children":2499},{"style":137},[2500],{"type":35,"value":1918},{"type":26,"tag":130,"props":2502,"children":2503},{"class":132,"line":205},[2504,2509,2513],{"type":26,"tag":130,"props":2505,"children":2506},{"style":722},[2507],{"type":35,"value":2508},"    GITHUB_TOKEN",{"type":26,"tag":130,"props":2510,"children":2511},{"style":137},[2512],{"type":35,"value":1893},{"type":26,"tag":130,"props":2514,"children":2515},{"style":165},[2516],{"type":35,"value":2517},"${{ secrets.GITHUB_TOKEN }}\n",{"type":26,"tag":130,"props":2519,"children":2520},{"class":132,"line":231},[2521,2525,2529],{"type":26,"tag":130,"props":2522,"children":2523},{"style":722},[2524],{"type":35,"value":2326},{"type":26,"tag":130,"props":2526,"children":2527},{"style":137},[2528],{"type":35,"value":1893},{"type":26,"tag":130,"props":2530,"children":2531},{"style":165},[2532],{"type":35,"value":2533},"mvn deploy\n",{"type":26,"tag":31,"props":2535,"children":2536},{},[2537,2539,2544],{"type":35,"value":2538},"Ensure your ",{"type":26,"tag":15,"props":2540,"children":2542},{"className":2541},[],[2543],{"type":35,"value":1832},{"type":35,"value":2545}," is configured for deployment (e.g., GitHub Packages).",{"type":26,"tag":38,"props":2547,"children":2549},{"id":2548},"step-5-committing-and-running-your-workflow",[2550],{"type":35,"value":2551},"Step 5: Committing and Running Your Workflow",{"type":26,"tag":31,"props":2553,"children":2554},{},[2555],{"type":35,"value":2556},"Commit your workflow file and push the changes:",{"type":26,"tag":121,"props":2558,"children":2562},{"code":2559,"language":2560,"meta":8,"className":2561,"style":8},"git add .github/workflows/maven-ci.yml\ngit commit -m \"Add Maven CI GitHub Actions workflow\"\ngit push\n","bash","language-bash shiki shiki-themes github-dark github-light",[2563],{"type":26,"tag":15,"props":2564,"children":2565},{"__ignoreMap":8},[2566,2584,2606],{"type":26,"tag":130,"props":2567,"children":2568},{"class":132,"line":133},[2569,2574,2579],{"type":26,"tag":130,"props":2570,"children":2571},{"style":154},[2572],{"type":35,"value":2573},"git",{"type":26,"tag":130,"props":2575,"children":2576},{"style":165},[2577],{"type":35,"value":2578}," add",{"type":26,"tag":130,"props":2580,"children":2581},{"style":165},[2582],{"type":35,"value":2583}," .github/workflows/maven-ci.yml\n",{"type":26,"tag":130,"props":2585,"children":2586},{"class":132,"line":176},[2587,2591,2596,2601],{"type":26,"tag":130,"props":2588,"children":2589},{"style":154},[2590],{"type":35,"value":2573},{"type":26,"tag":130,"props":2592,"children":2593},{"style":165},[2594],{"type":35,"value":2595}," commit",{"type":26,"tag":130,"props":2597,"children":2598},{"style":194},[2599],{"type":35,"value":2600}," -m",{"type":26,"tag":130,"props":2602,"children":2603},{"style":165},[2604],{"type":35,"value":2605}," \"Add Maven CI GitHub Actions workflow\"\n",{"type":26,"tag":130,"props":2607,"children":2608},{"class":132,"line":205},[2609,2613],{"type":26,"tag":130,"props":2610,"children":2611},{"style":154},[2612],{"type":35,"value":2573},{"type":26,"tag":130,"props":2614,"children":2615},{"style":165},[2616],{"type":35,"value":2617}," push\n",{"type":26,"tag":31,"props":2619,"children":2620},{},[2621,2623,2628],{"type":35,"value":2622},"Navigate to the ",{"type":26,"tag":994,"props":2624,"children":2625},{},[2626],{"type":35,"value":2627},"Actions",{"type":35,"value":2629}," tab on your GitHub repository to view and monitor your pipeline.",{"type":26,"tag":38,"props":2631,"children":2633},{"id":2632},"advantages-of-automating-java-builds",[2634],{"type":35,"value":2635},"Advantages of Automating Java Builds",{"type":26,"tag":896,"props":2637,"children":2638},{},[2639,2644,2649,2654],{"type":26,"tag":54,"props":2640,"children":2641},{},[2642],{"type":35,"value":2643},"Rapid feedback on code integration.",{"type":26,"tag":54,"props":2645,"children":2646},{},[2647],{"type":35,"value":2648},"Early identification of bugs and issues.",{"type":26,"tag":54,"props":2650,"children":2651},{},[2652],{"type":35,"value":2653},"Automated testing and deployment.",{"type":26,"tag":54,"props":2655,"children":2656},{},[2657],{"type":35,"value":2658},"Improved reliability and consistency.",{"type":26,"tag":38,"props":2660,"children":2662},{"id":2661},"pricing",[2663],{"type":35,"value":2664},"Pricing",{"type":26,"tag":31,"props":2666,"children":2667},{},[2668],{"type":35,"value":2669},"GitHub Actions offers a generous free tier suitable for most projects:",{"type":26,"tag":896,"props":2671,"children":2672},{},[2673,2699],{"type":26,"tag":54,"props":2674,"children":2675},{},[2676,2681],{"type":26,"tag":994,"props":2677,"children":2678},{},[2679],{"type":35,"value":2680},"Free Tier:",{"type":26,"tag":896,"props":2682,"children":2683},{},[2684,2689,2694],{"type":26,"tag":54,"props":2685,"children":2686},{},[2687],{"type":35,"value":2688},"2,000 minutes per month (private repositories).",{"type":26,"tag":54,"props":2690,"children":2691},{},[2692],{"type":35,"value":2693},"Unlimited minutes for public repositories.",{"type":26,"tag":54,"props":2695,"children":2696},{},[2697],{"type":35,"value":2698},"Free usage of GitHub-hosted runners for most common tasks.",{"type":26,"tag":54,"props":2700,"children":2701},{},[2702,2707],{"type":26,"tag":994,"props":2703,"children":2704},{},[2705],{"type":35,"value":2706},"Additional Minutes:",{"type":26,"tag":896,"props":2708,"children":2709},{},[2710,2715,2720],{"type":26,"tag":54,"props":2711,"children":2712},{},[2713],{"type":35,"value":2714},"$0.008 per minute for Linux runners.",{"type":26,"tag":54,"props":2716,"children":2717},{},[2718],{"type":35,"value":2719},"$0.016 per minute for Windows runners.",{"type":26,"tag":54,"props":2721,"children":2722},{},[2723],{"type":35,"value":2724},"$0.08 per minute for macOS runners.",{"type":26,"tag":31,"props":2726,"children":2727},{},[2728,2730,2737],{"type":35,"value":2729},"For detailed and up-to-date pricing, visit ",{"type":26,"tag":903,"props":2731,"children":2734},{"href":2732,"rel":2733},"https://github.com/pricing#actions",[907],[2735],{"type":35,"value":2736},"GitHub Actions Pricing",{"type":35,"value":1812},{"type":26,"tag":38,"props":2739,"children":2740},{"id":879},[2741],{"type":35,"value":882},{"type":26,"tag":31,"props":2743,"children":2744},{},[2745],{"type":35,"value":2746},"Using GitHub Actions with Maven provides an efficient and robust CI/CD pipeline, significantly improving your development lifecycle. Start implementing these practices today and streamline your Java application delivery.",{"type":26,"tag":889,"props":2748,"children":2749},{"id":891},[2750],{"type":35,"value":894},{"type":26,"tag":896,"props":2752,"children":2753},{},[2754,2764,2774],{"type":26,"tag":54,"props":2755,"children":2756},{},[2757],{"type":26,"tag":903,"props":2758,"children":2761},{"href":2759,"rel":2760},"https://docs.github.com/en/actions",[907],[2762],{"type":35,"value":2763},"GitHub Actions Documentation",{"type":26,"tag":54,"props":2765,"children":2766},{},[2767],{"type":26,"tag":903,"props":2768,"children":2771},{"href":2769,"rel":2770},"https://maven.apache.org/guides/",[907],[2772],{"type":35,"value":2773},"Maven Official Documentation",{"type":26,"tag":54,"props":2775,"children":2776},{},[2777],{"type":26,"tag":903,"props":2778,"children":2781},{"href":2779,"rel":2780},"https://docs.github.com/en/packages/working-with-a-github-packages-registry",[907],[2782],{"type":35,"value":2783},"Publishing Java Packages with GitHub Packages",{"type":26,"tag":932,"props":2785,"children":2786},{},[2787],{"type":35,"value":936},{"title":8,"searchDepth":176,"depth":176,"links":2789},[2790,2791,2792,2793,2794,2795,2796,2797,2798],{"id":1815,"depth":176,"text":1818},{"id":1842,"depth":176,"text":1845},{"id":2217,"depth":176,"text":2220},{"id":2282,"depth":176,"text":2285},{"id":2453,"depth":176,"text":2456},{"id":2548,"depth":176,"text":2551},{"id":2632,"depth":176,"text":2635},{"id":2661,"depth":176,"text":2664},{"id":879,"depth":176,"text":882},"content:posts:maven-and-github-actions.md","posts/maven-and-github-actions.md","posts/maven-and-github-actions",{"_path":2803,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":2804,"description":2805,"date":2806,"layout":12,"subtitle":2807,"image":2808,"optimized_image":2808,"category":15,"tags":2809,"author":21,"paginate":7,"body":2813,"_type":949,"_id":3651,"_source":951,"_file":3652,"_stem":3653,"_extension":954},"/posts/pattern-matching-sealed-classes-java21","A Guide to Pattern Matching and Sealed Classes in Java 21","A comprehensive introduction to pattern matching and sealed classes in Java 21, including practical examples and best practices.","2024-05-15T11:00:00.000Z","Writing Safer and More Expressive Java Code","/assets/img/uploads/java-pattern.matching.png",[15,17,2810,2811,2812],"pattern-matching","sealed-classes","java21",{"type":23,"children":2814,"toc":3637},[2815,2836,2842,2855,2861,2969,2975,3141,3147,3165,3170,3175,3181,3364,3370,3550,3555,3573,3579,3597,3601,3606,3610,3633],{"type":26,"tag":27,"props":2816,"children":2817},{},[2818],{"type":26,"tag":31,"props":2819,"children":2820},{},[2821,2823,2828,2829,2834],{"type":35,"value":2822},"Java 21 introduces powerful enhancements that improve readability, safety, and expressiveness in your code. Among these, ",{"type":26,"tag":994,"props":2824,"children":2825},{},[2826],{"type":35,"value":2827},"pattern matching",{"type":35,"value":1805},{"type":26,"tag":994,"props":2830,"children":2831},{},[2832],{"type":35,"value":2833},"sealed classes",{"type":35,"value":2835}," stand out, allowing developers to write concise, readable, and safe code. Let's explore both concepts with practical examples.",{"type":26,"tag":38,"props":2837,"children":2839},{"id":2838},"pattern-matching-for-switch",[2840],{"type":35,"value":2841},"Pattern Matching for Switch",{"type":26,"tag":31,"props":2843,"children":2844},{},[2845,2847,2853],{"type":35,"value":2846},"Pattern matching extends the classic ",{"type":26,"tag":15,"props":2848,"children":2850},{"className":2849},[],[2851],{"type":35,"value":2852},"switch",{"type":35,"value":2854}," statement, making code simpler and clearer by reducing the need for explicit casting and type checking.",{"type":26,"tag":1062,"props":2856,"children":2858},{"id":2857},"traditional-switch",[2859],{"type":35,"value":2860},"Traditional Switch",{"type":26,"tag":121,"props":2862,"children":2864},{"className":123,"code":2863,"language":17,"meta":8,"style":8},"Object obj = \"Hello\";\n\nif (obj instanceof String) {\n    String s = (String) obj;\n    System.out.println(s.toLowerCase());\n}\n",[2865],{"type":26,"tag":15,"props":2866,"children":2867},{"__ignoreMap":8},[2868,2890,2897,2919,2936,2962],{"type":26,"tag":130,"props":2869,"children":2870},{"class":132,"line":133},[2871,2876,2880,2885],{"type":26,"tag":130,"props":2872,"children":2873},{"style":137},[2874],{"type":35,"value":2875},"Object obj ",{"type":26,"tag":130,"props":2877,"children":2878},{"style":143},[2879],{"type":35,"value":146},{"type":26,"tag":130,"props":2881,"children":2882},{"style":165},[2883],{"type":35,"value":2884}," \"Hello\"",{"type":26,"tag":130,"props":2886,"children":2887},{"style":137},[2888],{"type":35,"value":2889},";\n",{"type":26,"tag":130,"props":2891,"children":2892},{"class":132,"line":176},[2893],{"type":26,"tag":130,"props":2894,"children":2895},{"emptyLinePlaceholder":298},[2896],{"type":35,"value":301},{"type":26,"tag":130,"props":2898,"children":2899},{"class":132,"line":205},[2900,2904,2909,2914],{"type":26,"tag":130,"props":2901,"children":2902},{"style":143},[2903],{"type":35,"value":346},{"type":26,"tag":130,"props":2905,"children":2906},{"style":137},[2907],{"type":35,"value":2908}," (obj ",{"type":26,"tag":130,"props":2910,"children":2911},{"style":143},[2912],{"type":35,"value":2913},"instanceof",{"type":26,"tag":130,"props":2915,"children":2916},{"style":137},[2917],{"type":35,"value":2918}," String) {\n",{"type":26,"tag":130,"props":2920,"children":2921},{"class":132,"line":231},[2922,2927,2931],{"type":26,"tag":130,"props":2923,"children":2924},{"style":137},[2925],{"type":35,"value":2926},"    String s ",{"type":26,"tag":130,"props":2928,"children":2929},{"style":143},[2930],{"type":35,"value":146},{"type":26,"tag":130,"props":2932,"children":2933},{"style":137},[2934],{"type":35,"value":2935}," (String) obj;\n",{"type":26,"tag":130,"props":2937,"children":2938},{"class":132,"line":364},[2939,2944,2948,2953,2958],{"type":26,"tag":130,"props":2940,"children":2941},{"style":137},[2942],{"type":35,"value":2943},"    System.out.",{"type":26,"tag":130,"props":2945,"children":2946},{"style":154},[2947],{"type":35,"value":1554},{"type":26,"tag":130,"props":2949,"children":2950},{"style":137},[2951],{"type":35,"value":2952},"(s.",{"type":26,"tag":130,"props":2954,"children":2955},{"style":154},[2956],{"type":35,"value":2957},"toLowerCase",{"type":26,"tag":130,"props":2959,"children":2960},{"style":137},[2961],{"type":35,"value":338},{"type":26,"tag":130,"props":2963,"children":2964},{"class":132,"line":374},[2965],{"type":26,"tag":130,"props":2966,"children":2967},{"style":137},[2968],{"type":35,"value":380},{"type":26,"tag":1062,"props":2970,"children":2972},{"id":2971},"pattern-matching-switch",[2973],{"type":35,"value":2974},"Pattern Matching Switch",{"type":26,"tag":121,"props":2976,"children":2978},{"className":123,"code":2977,"language":17,"meta":8,"style":8},"Object obj = \"Hello\";\n\nswitch (obj) {\n    case String s -> System.out.println(s.toLowerCase());\n    case Integer i -> System.out.println(i + 1);\n    default -> System.out.println(\"Unknown type\");\n}\n",[2979],{"type":26,"tag":15,"props":2980,"children":2981},{"__ignoreMap":8},[2982,3001,3008,3020,3057,3100,3134],{"type":26,"tag":130,"props":2983,"children":2984},{"class":132,"line":133},[2985,2989,2993,2997],{"type":26,"tag":130,"props":2986,"children":2987},{"style":137},[2988],{"type":35,"value":2875},{"type":26,"tag":130,"props":2990,"children":2991},{"style":143},[2992],{"type":35,"value":146},{"type":26,"tag":130,"props":2994,"children":2995},{"style":165},[2996],{"type":35,"value":2884},{"type":26,"tag":130,"props":2998,"children":2999},{"style":137},[3000],{"type":35,"value":2889},{"type":26,"tag":130,"props":3002,"children":3003},{"class":132,"line":176},[3004],{"type":26,"tag":130,"props":3005,"children":3006},{"emptyLinePlaceholder":298},[3007],{"type":35,"value":301},{"type":26,"tag":130,"props":3009,"children":3010},{"class":132,"line":205},[3011,3015],{"type":26,"tag":130,"props":3012,"children":3013},{"style":143},[3014],{"type":35,"value":2852},{"type":26,"tag":130,"props":3016,"children":3017},{"style":137},[3018],{"type":35,"value":3019}," (obj) {\n",{"type":26,"tag":130,"props":3021,"children":3022},{"class":132,"line":231},[3023,3028,3033,3037,3041,3045,3049,3053],{"type":26,"tag":130,"props":3024,"children":3025},{"style":143},[3026],{"type":35,"value":3027},"    case",{"type":26,"tag":130,"props":3029,"children":3030},{"style":137},[3031],{"type":35,"value":3032}," String s ",{"type":26,"tag":130,"props":3034,"children":3035},{"style":143},[3036],{"type":35,"value":1454},{"type":26,"tag":130,"props":3038,"children":3039},{"style":137},[3040],{"type":35,"value":1549},{"type":26,"tag":130,"props":3042,"children":3043},{"style":154},[3044],{"type":35,"value":1554},{"type":26,"tag":130,"props":3046,"children":3047},{"style":137},[3048],{"type":35,"value":2952},{"type":26,"tag":130,"props":3050,"children":3051},{"style":154},[3052],{"type":35,"value":2957},{"type":26,"tag":130,"props":3054,"children":3055},{"style":137},[3056],{"type":35,"value":338},{"type":26,"tag":130,"props":3058,"children":3059},{"class":132,"line":364},[3060,3064,3069,3073,3077,3081,3086,3091,3096],{"type":26,"tag":130,"props":3061,"children":3062},{"style":143},[3063],{"type":35,"value":3027},{"type":26,"tag":130,"props":3065,"children":3066},{"style":137},[3067],{"type":35,"value":3068}," Integer i ",{"type":26,"tag":130,"props":3070,"children":3071},{"style":143},[3072],{"type":35,"value":1454},{"type":26,"tag":130,"props":3074,"children":3075},{"style":137},[3076],{"type":35,"value":1549},{"type":26,"tag":130,"props":3078,"children":3079},{"style":154},[3080],{"type":35,"value":1554},{"type":26,"tag":130,"props":3082,"children":3083},{"style":137},[3084],{"type":35,"value":3085},"(i ",{"type":26,"tag":130,"props":3087,"children":3088},{"style":143},[3089],{"type":35,"value":3090},"+",{"type":26,"tag":130,"props":3092,"children":3093},{"style":194},[3094],{"type":35,"value":3095}," 1",{"type":26,"tag":130,"props":3097,"children":3098},{"style":137},[3099],{"type":35,"value":173},{"type":26,"tag":130,"props":3101,"children":3102},{"class":132,"line":374},[3103,3108,3113,3117,3121,3125,3130],{"type":26,"tag":130,"props":3104,"children":3105},{"style":143},[3106],{"type":35,"value":3107},"    default",{"type":26,"tag":130,"props":3109,"children":3110},{"style":143},[3111],{"type":35,"value":3112}," ->",{"type":26,"tag":130,"props":3114,"children":3115},{"style":137},[3116],{"type":35,"value":1549},{"type":26,"tag":130,"props":3118,"children":3119},{"style":154},[3120],{"type":35,"value":1554},{"type":26,"tag":130,"props":3122,"children":3123},{"style":137},[3124],{"type":35,"value":162},{"type":26,"tag":130,"props":3126,"children":3127},{"style":165},[3128],{"type":35,"value":3129},"\"Unknown type\"",{"type":26,"tag":130,"props":3131,"children":3132},{"style":137},[3133],{"type":35,"value":173},{"type":26,"tag":130,"props":3135,"children":3136},{"class":132,"line":1353},[3137],{"type":26,"tag":130,"props":3138,"children":3139},{"style":137},[3140],{"type":35,"value":380},{"type":26,"tag":1062,"props":3142,"children":3144},{"id":3143},"benefits",[3145],{"type":35,"value":3146},"Benefits:",{"type":26,"tag":896,"props":3148,"children":3149},{},[3150,3155,3160],{"type":26,"tag":54,"props":3151,"children":3152},{},[3153],{"type":35,"value":3154},"Reduced boilerplate code",{"type":26,"tag":54,"props":3156,"children":3157},{},[3158],{"type":35,"value":3159},"Enhanced readability",{"type":26,"tag":54,"props":3161,"children":3162},{},[3163],{"type":35,"value":3164},"Improved type safety",{"type":26,"tag":38,"props":3166,"children":3167},{"id":2811},[3168],{"type":35,"value":3169},"Sealed Classes",{"type":26,"tag":31,"props":3171,"children":3172},{},[3173],{"type":35,"value":3174},"Sealed classes allow you to define which subclasses or implementations are permitted. This helps in modeling clear and controlled domain hierarchies.",{"type":26,"tag":1062,"props":3176,"children":3178},{"id":3177},"declaring-a-sealed-class",[3179],{"type":35,"value":3180},"Declaring a Sealed Class",{"type":26,"tag":121,"props":3182,"children":3184},{"className":123,"code":3183,"language":17,"meta":8,"style":8},"public sealed abstract class Shape\n    permits Circle, Rectangle {}\n\npublic final class Circle extends Shape {\n    double radius;\n}\n\npublic final class Rectangle extends Shape {\n    double length, width;\n}\n",[3185],{"type":26,"tag":15,"props":3186,"children":3187},{"__ignoreMap":8},[3188,3216,3244,3251,3286,3299,3306,3313,3345,3357],{"type":26,"tag":130,"props":3189,"children":3190},{"class":132,"line":133},[3191,3196,3201,3206,3211],{"type":26,"tag":130,"props":3192,"children":3193},{"style":143},[3194],{"type":35,"value":3195},"public",{"type":26,"tag":130,"props":3197,"children":3198},{"style":143},[3199],{"type":35,"value":3200}," sealed",{"type":26,"tag":130,"props":3202,"children":3203},{"style":143},[3204],{"type":35,"value":3205}," abstract",{"type":26,"tag":130,"props":3207,"children":3208},{"style":143},[3209],{"type":35,"value":3210}," class",{"type":26,"tag":130,"props":3212,"children":3213},{"style":154},[3214],{"type":35,"value":3215}," Shape\n",{"type":26,"tag":130,"props":3217,"children":3218},{"class":132,"line":176},[3219,3224,3229,3234,3239],{"type":26,"tag":130,"props":3220,"children":3221},{"style":143},[3222],{"type":35,"value":3223},"    permits",{"type":26,"tag":130,"props":3225,"children":3226},{"style":154},[3227],{"type":35,"value":3228}," Circle",{"type":26,"tag":130,"props":3230,"children":3231},{"style":137},[3232],{"type":35,"value":3233},", ",{"type":26,"tag":130,"props":3235,"children":3236},{"style":154},[3237],{"type":35,"value":3238},"Rectangle",{"type":26,"tag":130,"props":3240,"children":3241},{"style":137},[3242],{"type":35,"value":3243}," {}\n",{"type":26,"tag":130,"props":3245,"children":3246},{"class":132,"line":205},[3247],{"type":26,"tag":130,"props":3248,"children":3249},{"emptyLinePlaceholder":298},[3250],{"type":35,"value":301},{"type":26,"tag":130,"props":3252,"children":3253},{"class":132,"line":231},[3254,3258,3263,3267,3271,3276,3281],{"type":26,"tag":130,"props":3255,"children":3256},{"style":143},[3257],{"type":35,"value":3195},{"type":26,"tag":130,"props":3259,"children":3260},{"style":143},[3261],{"type":35,"value":3262}," final",{"type":26,"tag":130,"props":3264,"children":3265},{"style":143},[3266],{"type":35,"value":3210},{"type":26,"tag":130,"props":3268,"children":3269},{"style":154},[3270],{"type":35,"value":3228},{"type":26,"tag":130,"props":3272,"children":3273},{"style":143},[3274],{"type":35,"value":3275}," extends",{"type":26,"tag":130,"props":3277,"children":3278},{"style":154},[3279],{"type":35,"value":3280}," Shape",{"type":26,"tag":130,"props":3282,"children":3283},{"style":137},[3284],{"type":35,"value":3285}," {\n",{"type":26,"tag":130,"props":3287,"children":3288},{"class":132,"line":364},[3289,3294],{"type":26,"tag":130,"props":3290,"children":3291},{"style":143},[3292],{"type":35,"value":3293},"    double",{"type":26,"tag":130,"props":3295,"children":3296},{"style":137},[3297],{"type":35,"value":3298}," radius;\n",{"type":26,"tag":130,"props":3300,"children":3301},{"class":132,"line":374},[3302],{"type":26,"tag":130,"props":3303,"children":3304},{"style":137},[3305],{"type":35,"value":380},{"type":26,"tag":130,"props":3307,"children":3308},{"class":132,"line":1353},[3309],{"type":26,"tag":130,"props":3310,"children":3311},{"emptyLinePlaceholder":298},[3312],{"type":35,"value":301},{"type":26,"tag":130,"props":3314,"children":3315},{"class":132,"line":1361},[3316,3320,3324,3328,3333,3337,3341],{"type":26,"tag":130,"props":3317,"children":3318},{"style":143},[3319],{"type":35,"value":3195},{"type":26,"tag":130,"props":3321,"children":3322},{"style":143},[3323],{"type":35,"value":3262},{"type":26,"tag":130,"props":3325,"children":3326},{"style":143},[3327],{"type":35,"value":3210},{"type":26,"tag":130,"props":3329,"children":3330},{"style":154},[3331],{"type":35,"value":3332}," Rectangle",{"type":26,"tag":130,"props":3334,"children":3335},{"style":143},[3336],{"type":35,"value":3275},{"type":26,"tag":130,"props":3338,"children":3339},{"style":154},[3340],{"type":35,"value":3280},{"type":26,"tag":130,"props":3342,"children":3343},{"style":137},[3344],{"type":35,"value":3285},{"type":26,"tag":130,"props":3346,"children":3347},{"class":132,"line":1994},[3348,3352],{"type":26,"tag":130,"props":3349,"children":3350},{"style":143},[3351],{"type":35,"value":3293},{"type":26,"tag":130,"props":3353,"children":3354},{"style":137},[3355],{"type":35,"value":3356}," length, width;\n",{"type":26,"tag":130,"props":3358,"children":3359},{"class":132,"line":2007},[3360],{"type":26,"tag":130,"props":3361,"children":3362},{"style":137},[3363],{"type":35,"value":380},{"type":26,"tag":1062,"props":3365,"children":3367},{"id":3366},"using-pattern-matching-with-sealed-classes",[3368],{"type":35,"value":3369},"Using Pattern Matching with Sealed Classes",{"type":26,"tag":121,"props":3371,"children":3373},{"className":123,"code":3372,"language":17,"meta":8,"style":8},"Shape shape = new Circle();\n\ndouble area = switch (shape) {\n    case Circle c -> Math.PI * c.radius * c.radius;\n    case Rectangle r -> r.length * r.width;\n};\n\nSystem.out.println(\"Area: \" + area);\n",[3374],{"type":26,"tag":15,"props":3375,"children":3376},{"__ignoreMap":8},[3377,3401,3408,3435,3475,3505,3513,3520],{"type":26,"tag":130,"props":3378,"children":3379},{"class":132,"line":133},[3380,3385,3389,3393,3397],{"type":26,"tag":130,"props":3381,"children":3382},{"style":137},[3383],{"type":35,"value":3384},"Shape shape ",{"type":26,"tag":130,"props":3386,"children":3387},{"style":143},[3388],{"type":35,"value":146},{"type":26,"tag":130,"props":3390,"children":3391},{"style":143},[3392],{"type":35,"value":627},{"type":26,"tag":130,"props":3394,"children":3395},{"style":154},[3396],{"type":35,"value":3228},{"type":26,"tag":130,"props":3398,"children":3399},{"style":137},[3400],{"type":35,"value":256},{"type":26,"tag":130,"props":3402,"children":3403},{"class":132,"line":176},[3404],{"type":26,"tag":130,"props":3405,"children":3406},{"emptyLinePlaceholder":298},[3407],{"type":35,"value":301},{"type":26,"tag":130,"props":3409,"children":3410},{"class":132,"line":205},[3411,3416,3421,3425,3430],{"type":26,"tag":130,"props":3412,"children":3413},{"style":143},[3414],{"type":35,"value":3415},"double",{"type":26,"tag":130,"props":3417,"children":3418},{"style":137},[3419],{"type":35,"value":3420}," area ",{"type":26,"tag":130,"props":3422,"children":3423},{"style":143},[3424],{"type":35,"value":146},{"type":26,"tag":130,"props":3426,"children":3427},{"style":143},[3428],{"type":35,"value":3429}," switch",{"type":26,"tag":130,"props":3431,"children":3432},{"style":137},[3433],{"type":35,"value":3434}," (shape) {\n",{"type":26,"tag":130,"props":3436,"children":3437},{"class":132,"line":231},[3438,3442,3447,3451,3456,3461,3466,3470],{"type":26,"tag":130,"props":3439,"children":3440},{"style":143},[3441],{"type":35,"value":3027},{"type":26,"tag":130,"props":3443,"children":3444},{"style":137},[3445],{"type":35,"value":3446}," Circle c ",{"type":26,"tag":130,"props":3448,"children":3449},{"style":143},[3450],{"type":35,"value":1454},{"type":26,"tag":130,"props":3452,"children":3453},{"style":137},[3454],{"type":35,"value":3455}," Math.PI ",{"type":26,"tag":130,"props":3457,"children":3458},{"style":143},[3459],{"type":35,"value":3460},"*",{"type":26,"tag":130,"props":3462,"children":3463},{"style":137},[3464],{"type":35,"value":3465}," c.radius ",{"type":26,"tag":130,"props":3467,"children":3468},{"style":143},[3469],{"type":35,"value":3460},{"type":26,"tag":130,"props":3471,"children":3472},{"style":137},[3473],{"type":35,"value":3474}," c.radius;\n",{"type":26,"tag":130,"props":3476,"children":3477},{"class":132,"line":364},[3478,3482,3487,3491,3496,3500],{"type":26,"tag":130,"props":3479,"children":3480},{"style":143},[3481],{"type":35,"value":3027},{"type":26,"tag":130,"props":3483,"children":3484},{"style":137},[3485],{"type":35,"value":3486}," Rectangle r ",{"type":26,"tag":130,"props":3488,"children":3489},{"style":143},[3490],{"type":35,"value":1454},{"type":26,"tag":130,"props":3492,"children":3493},{"style":137},[3494],{"type":35,"value":3495}," r.length ",{"type":26,"tag":130,"props":3497,"children":3498},{"style":143},[3499],{"type":35,"value":3460},{"type":26,"tag":130,"props":3501,"children":3502},{"style":137},[3503],{"type":35,"value":3504}," r.width;\n",{"type":26,"tag":130,"props":3506,"children":3507},{"class":132,"line":374},[3508],{"type":26,"tag":130,"props":3509,"children":3510},{"style":137},[3511],{"type":35,"value":3512},"};\n",{"type":26,"tag":130,"props":3514,"children":3515},{"class":132,"line":1353},[3516],{"type":26,"tag":130,"props":3517,"children":3518},{"emptyLinePlaceholder":298},[3519],{"type":35,"value":301},{"type":26,"tag":130,"props":3521,"children":3522},{"class":132,"line":1361},[3523,3528,3532,3536,3541,3545],{"type":26,"tag":130,"props":3524,"children":3525},{"style":137},[3526],{"type":35,"value":3527},"System.out.",{"type":26,"tag":130,"props":3529,"children":3530},{"style":154},[3531],{"type":35,"value":1554},{"type":26,"tag":130,"props":3533,"children":3534},{"style":137},[3535],{"type":35,"value":162},{"type":26,"tag":130,"props":3537,"children":3538},{"style":165},[3539],{"type":35,"value":3540},"\"Area: \"",{"type":26,"tag":130,"props":3542,"children":3543},{"style":143},[3544],{"type":35,"value":1568},{"type":26,"tag":130,"props":3546,"children":3547},{"style":137},[3548],{"type":35,"value":3549}," area);\n",{"type":26,"tag":1062,"props":3551,"children":3553},{"id":3552},"benefits-1",[3554],{"type":35,"value":3146},{"type":26,"tag":896,"props":3556,"children":3557},{},[3558,3563,3568],{"type":26,"tag":54,"props":3559,"children":3560},{},[3561],{"type":35,"value":3562},"Enhanced clarity of inheritance hierarchies",{"type":26,"tag":54,"props":3564,"children":3565},{},[3566],{"type":35,"value":3567},"Compile-time enforcement of permitted subclasses",{"type":26,"tag":54,"props":3569,"children":3570},{},[3571],{"type":35,"value":3572},"Simplified, safer code when used with pattern matching",{"type":26,"tag":38,"props":3574,"children":3576},{"id":3575},"practical-applications",[3577],{"type":35,"value":3578},"Practical Applications",{"type":26,"tag":896,"props":3580,"children":3581},{},[3582,3587,3592],{"type":26,"tag":54,"props":3583,"children":3584},{},[3585],{"type":35,"value":3586},"Domain modeling with restricted class hierarchies",{"type":26,"tag":54,"props":3588,"children":3589},{},[3590],{"type":35,"value":3591},"Type-safe parsing and processing of structured data",{"type":26,"tag":54,"props":3593,"children":3594},{},[3595],{"type":35,"value":3596},"Cleaner implementations of polymorphic behavior",{"type":26,"tag":38,"props":3598,"children":3599},{"id":879},[3600],{"type":35,"value":882},{"type":26,"tag":31,"props":3602,"children":3603},{},[3604],{"type":35,"value":3605},"Pattern matching and sealed classes provide significant improvements in Java 21, helping you write cleaner, safer, and more maintainable code. Mastering these tools allows developers to leverage the full expressive power of modern Java.",{"type":26,"tag":889,"props":3607,"children":3608},{"id":891},[3609],{"type":35,"value":894},{"type":26,"tag":896,"props":3611,"children":3612},{},[3613,3623],{"type":26,"tag":54,"props":3614,"children":3615},{},[3616],{"type":26,"tag":903,"props":3617,"children":3620},{"href":3618,"rel":3619},"https://openjdk.org/jeps/441",[907],[3621],{"type":35,"value":3622},"Java 21 Pattern Matching JEP",{"type":26,"tag":54,"props":3624,"children":3625},{},[3626],{"type":26,"tag":903,"props":3627,"children":3630},{"href":3628,"rel":3629},"https://openjdk.org/jeps/409",[907],[3631],{"type":35,"value":3632},"Java 21 Sealed Classes JEP",{"type":26,"tag":932,"props":3634,"children":3635},{},[3636],{"type":35,"value":936},{"title":8,"searchDepth":176,"depth":176,"links":3638},[3639,3644,3649,3650],{"id":2838,"depth":176,"text":2841,"children":3640},[3641,3642,3643],{"id":2857,"depth":205,"text":2860},{"id":2971,"depth":205,"text":2974},{"id":3143,"depth":205,"text":3146},{"id":2811,"depth":176,"text":3169,"children":3645},[3646,3647,3648],{"id":3177,"depth":205,"text":3180},{"id":3366,"depth":205,"text":3369},{"id":3552,"depth":205,"text":3146},{"id":3575,"depth":176,"text":3578},{"id":879,"depth":176,"text":882},"content:posts:pattern-matching-sealed-classes-java21.md","posts/pattern-matching-sealed-classes-java21.md","posts/pattern-matching-sealed-classes-java21",{"_path":3655,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":3656,"description":3657,"date":3658,"layout":12,"subtitle":3659,"image":3660,"optimized_image":3660,"category":15,"tags":3661,"author":21,"paginate":7,"body":3665,"_type":949,"_id":5438,"_source":951,"_file":5439,"_stem":5440,"_extension":954},"/posts/async-java-completable-vs-reactive","Asynchronous Programming in Java: CompletableFuture vs Reactive Streams","A deep dive into asynchronous programming in Java comparing CompletableFuture and Reactive Streams, with examples and output.","2024-04-15T11:00:00.000Z","Choosing the Right Tool for Concurrency in Modern Java","/assets/img/uploads/java-async.png",[15,17,3662,3663,3664],"asynchronous","reactive","concurrency",{"type":23,"children":3666,"toc":5424},[3667,3689,3695,3705,3711,4062,4070,4078,4084,4366,4373,4381,4387,4395,4413,4421,4439,4443,4449,4483,4489,4790,4797,4805,4811,5143,5150,5158,5164,5171,5189,5196,5214,5217,5223,5352,5355,5359,5378,5383,5387,5420],{"type":26,"tag":27,"props":3668,"children":3669},{},[3670],{"type":26,"tag":31,"props":3671,"children":3672},{},[3673,3675,3681,3682,3687],{"type":35,"value":3674},"Asynchronous programming enables applications to execute non-blocking operations, crucial for performance in modern, concurrent systems. In Java, two powerful tools are commonly used: ",{"type":26,"tag":15,"props":3676,"children":3678},{"className":3677},[],[3679],{"type":35,"value":3680},"CompletableFuture",{"type":35,"value":1805},{"type":26,"tag":994,"props":3683,"children":3684},{},[3685],{"type":35,"value":3686},"Reactive Streams",{"type":35,"value":3688}," (e.g., Project Reactor or RxJava). In this post, we’ll compare both approaches through real code examples and output results.",{"type":26,"tag":38,"props":3690,"children":3692},{"id":3691},"_1-completablefuture-javas-built-in-promise-api",[3693],{"type":35,"value":3694},"1. CompletableFuture: Java’s Built-in Promise API",{"type":26,"tag":31,"props":3696,"children":3697},{},[3698,3703],{"type":26,"tag":15,"props":3699,"children":3701},{"className":3700},[],[3702],{"type":35,"value":3680},{"type":35,"value":3704}," is a class introduced in Java 8 to write asynchronous, non-blocking code. It's suitable for simple async flows and integrates well with imperative codebases.",{"type":26,"tag":1062,"props":3706,"children":3708},{"id":3707},"example-1-basic-async-execution",[3709],{"type":35,"value":3710},"Example 1: Basic Async Execution",{"type":26,"tag":121,"props":3712,"children":3714},{"code":3713,"language":17,"meta":8,"className":123,"style":8},"import java.util.concurrent.CompletableFuture;\n\npublic class CompletableFutureDemo {\n    public static void main(String[] args) {\n        CompletableFuture\u003CString> future = CompletableFuture.supplyAsync(() -> {\n            sleep(1000);\n            return \"Hello from CompletableFuture!\";\n        });\n\n        future.thenAccept(System.out::println);\n        sleep(1500); // wait for completion\n    }\n\n    static void sleep(long millis) {\n        try { Thread.sleep(millis); } catch (InterruptedException e) { }\n    }\n}\n",[3715],{"type":26,"tag":15,"props":3716,"children":3717},{"__ignoreMap":8},[3718,3730,3737,3757,3804,3848,3868,3885,3893,3900,3928,3955,3963,3970,4005,4048,4055],{"type":26,"tag":130,"props":3719,"children":3720},{"class":132,"line":133},[3721,3725],{"type":26,"tag":130,"props":3722,"children":3723},{"style":143},[3724],{"type":35,"value":287},{"type":26,"tag":130,"props":3726,"children":3727},{"style":137},[3728],{"type":35,"value":3729}," java.util.concurrent.CompletableFuture;\n",{"type":26,"tag":130,"props":3731,"children":3732},{"class":132,"line":176},[3733],{"type":26,"tag":130,"props":3734,"children":3735},{"emptyLinePlaceholder":298},[3736],{"type":35,"value":301},{"type":26,"tag":130,"props":3738,"children":3739},{"class":132,"line":205},[3740,3744,3748,3753],{"type":26,"tag":130,"props":3741,"children":3742},{"style":143},[3743],{"type":35,"value":3195},{"type":26,"tag":130,"props":3745,"children":3746},{"style":143},[3747],{"type":35,"value":3210},{"type":26,"tag":130,"props":3749,"children":3750},{"style":154},[3751],{"type":35,"value":3752}," CompletableFutureDemo",{"type":26,"tag":130,"props":3754,"children":3755},{"style":137},[3756],{"type":35,"value":3285},{"type":26,"tag":130,"props":3758,"children":3759},{"class":132,"line":231},[3760,3765,3770,3775,3780,3784,3788,3793,3799],{"type":26,"tag":130,"props":3761,"children":3762},{"style":143},[3763],{"type":35,"value":3764},"    public",{"type":26,"tag":130,"props":3766,"children":3767},{"style":143},[3768],{"type":35,"value":3769}," static",{"type":26,"tag":130,"props":3771,"children":3772},{"style":143},[3773],{"type":35,"value":3774}," void",{"type":26,"tag":130,"props":3776,"children":3777},{"style":154},[3778],{"type":35,"value":3779}," main",{"type":26,"tag":130,"props":3781,"children":3782},{"style":137},[3783],{"type":35,"value":162},{"type":26,"tag":130,"props":3785,"children":3786},{"style":143},[3787],{"type":35,"value":1426},{"type":26,"tag":130,"props":3789,"children":3790},{"style":137},[3791],{"type":35,"value":3792},"[] ",{"type":26,"tag":130,"props":3794,"children":3796},{"style":3795},"--shiki-default:#FFAB70;--shiki-light:#E36209",[3797],{"type":35,"value":3798},"args",{"type":26,"tag":130,"props":3800,"children":3801},{"style":137},[3802],{"type":35,"value":3803},") {\n",{"type":26,"tag":130,"props":3805,"children":3806},{"class":132,"line":364},[3807,3812,3816,3821,3825,3830,3835,3840,3844],{"type":26,"tag":130,"props":3808,"children":3809},{"style":137},[3810],{"type":35,"value":3811},"        CompletableFuture\u003C",{"type":26,"tag":130,"props":3813,"children":3814},{"style":143},[3815],{"type":35,"value":1426},{"type":26,"tag":130,"props":3817,"children":3818},{"style":137},[3819],{"type":35,"value":3820},"> future ",{"type":26,"tag":130,"props":3822,"children":3823},{"style":143},[3824],{"type":35,"value":146},{"type":26,"tag":130,"props":3826,"children":3827},{"style":137},[3828],{"type":35,"value":3829}," CompletableFuture.",{"type":26,"tag":130,"props":3831,"children":3832},{"style":154},[3833],{"type":35,"value":3834},"supplyAsync",{"type":26,"tag":130,"props":3836,"children":3837},{"style":137},[3838],{"type":35,"value":3839},"(() ",{"type":26,"tag":130,"props":3841,"children":3842},{"style":143},[3843],{"type":35,"value":1454},{"type":26,"tag":130,"props":3845,"children":3846},{"style":137},[3847],{"type":35,"value":3285},{"type":26,"tag":130,"props":3849,"children":3850},{"class":132,"line":374},[3851,3856,3860,3864],{"type":26,"tag":130,"props":3852,"children":3853},{"style":154},[3854],{"type":35,"value":3855},"            sleep",{"type":26,"tag":130,"props":3857,"children":3858},{"style":137},[3859],{"type":35,"value":162},{"type":26,"tag":130,"props":3861,"children":3862},{"style":194},[3863],{"type":35,"value":1280},{"type":26,"tag":130,"props":3865,"children":3866},{"style":137},[3867],{"type":35,"value":173},{"type":26,"tag":130,"props":3869,"children":3870},{"class":132,"line":1353},[3871,3876,3881],{"type":26,"tag":130,"props":3872,"children":3873},{"style":143},[3874],{"type":35,"value":3875},"            return",{"type":26,"tag":130,"props":3877,"children":3878},{"style":165},[3879],{"type":35,"value":3880}," \"Hello from CompletableFuture!\"",{"type":26,"tag":130,"props":3882,"children":3883},{"style":137},[3884],{"type":35,"value":2889},{"type":26,"tag":130,"props":3886,"children":3887},{"class":132,"line":1361},[3888],{"type":26,"tag":130,"props":3889,"children":3890},{"style":137},[3891],{"type":35,"value":3892},"        });\n",{"type":26,"tag":130,"props":3894,"children":3895},{"class":132,"line":1994},[3896],{"type":26,"tag":130,"props":3897,"children":3898},{"emptyLinePlaceholder":298},[3899],{"type":35,"value":301},{"type":26,"tag":130,"props":3901,"children":3902},{"class":132,"line":2007},[3903,3908,3913,3918,3923],{"type":26,"tag":130,"props":3904,"children":3905},{"style":137},[3906],{"type":35,"value":3907},"        future.",{"type":26,"tag":130,"props":3909,"children":3910},{"style":154},[3911],{"type":35,"value":3912},"thenAccept",{"type":26,"tag":130,"props":3914,"children":3915},{"style":137},[3916],{"type":35,"value":3917},"(System.out",{"type":26,"tag":130,"props":3919,"children":3920},{"style":143},[3921],{"type":35,"value":3922},"::",{"type":26,"tag":130,"props":3924,"children":3925},{"style":137},[3926],{"type":35,"value":3927},"println);\n",{"type":26,"tag":130,"props":3929,"children":3930},{"class":132,"line":2020},[3931,3936,3940,3945,3950],{"type":26,"tag":130,"props":3932,"children":3933},{"style":154},[3934],{"type":35,"value":3935},"        sleep",{"type":26,"tag":130,"props":3937,"children":3938},{"style":137},[3939],{"type":35,"value":162},{"type":26,"tag":130,"props":3941,"children":3942},{"style":194},[3943],{"type":35,"value":3944},"1500",{"type":26,"tag":130,"props":3946,"children":3947},{"style":137},[3948],{"type":35,"value":3949},"); ",{"type":26,"tag":130,"props":3951,"children":3952},{"style":368},[3953],{"type":35,"value":3954},"// wait for completion\n",{"type":26,"tag":130,"props":3956,"children":3957},{"class":132,"line":2038},[3958],{"type":26,"tag":130,"props":3959,"children":3960},{"style":137},[3961],{"type":35,"value":3962},"    }\n",{"type":26,"tag":130,"props":3964,"children":3965},{"class":132,"line":2046},[3966],{"type":26,"tag":130,"props":3967,"children":3968},{"emptyLinePlaceholder":298},[3969],{"type":35,"value":301},{"type":26,"tag":130,"props":3971,"children":3972},{"class":132,"line":2059},[3973,3978,3982,3987,3991,3996,4001],{"type":26,"tag":130,"props":3974,"children":3975},{"style":143},[3976],{"type":35,"value":3977},"    static",{"type":26,"tag":130,"props":3979,"children":3980},{"style":143},[3981],{"type":35,"value":3774},{"type":26,"tag":130,"props":3983,"children":3984},{"style":154},[3985],{"type":35,"value":3986}," sleep",{"type":26,"tag":130,"props":3988,"children":3989},{"style":137},[3990],{"type":35,"value":162},{"type":26,"tag":130,"props":3992,"children":3993},{"style":143},[3994],{"type":35,"value":3995},"long",{"type":26,"tag":130,"props":3997,"children":3998},{"style":3795},[3999],{"type":35,"value":4000}," millis",{"type":26,"tag":130,"props":4002,"children":4003},{"style":137},[4004],{"type":35,"value":3803},{"type":26,"tag":130,"props":4006,"children":4007},{"class":132,"line":2082},[4008,4013,4018,4023,4028,4033,4038,4043],{"type":26,"tag":130,"props":4009,"children":4010},{"style":143},[4011],{"type":35,"value":4012},"        try",{"type":26,"tag":130,"props":4014,"children":4015},{"style":137},[4016],{"type":35,"value":4017}," { Thread.",{"type":26,"tag":130,"props":4019,"children":4020},{"style":154},[4021],{"type":35,"value":4022},"sleep",{"type":26,"tag":130,"props":4024,"children":4025},{"style":137},[4026],{"type":35,"value":4027},"(millis); } ",{"type":26,"tag":130,"props":4029,"children":4030},{"style":143},[4031],{"type":35,"value":4032},"catch",{"type":26,"tag":130,"props":4034,"children":4035},{"style":137},[4036],{"type":35,"value":4037}," (InterruptedException ",{"type":26,"tag":130,"props":4039,"children":4040},{"style":3795},[4041],{"type":35,"value":4042},"e",{"type":26,"tag":130,"props":4044,"children":4045},{"style":137},[4046],{"type":35,"value":4047},") { }\n",{"type":26,"tag":130,"props":4049,"children":4050},{"class":132,"line":2103},[4051],{"type":26,"tag":130,"props":4052,"children":4053},{"style":137},[4054],{"type":35,"value":3962},{"type":26,"tag":130,"props":4056,"children":4057},{"class":132,"line":2121},[4058],{"type":26,"tag":130,"props":4059,"children":4060},{"style":137},[4061],{"type":35,"value":380},{"type":26,"tag":31,"props":4063,"children":4064},{},[4065],{"type":26,"tag":994,"props":4066,"children":4067},{},[4068],{"type":35,"value":4069},"Output:",{"type":26,"tag":121,"props":4071,"children":4073},{"code":4072},"Hello from CompletableFuture!\n",[4074],{"type":26,"tag":15,"props":4075,"children":4076},{"__ignoreMap":8},[4077],{"type":35,"value":4072},{"type":26,"tag":1062,"props":4079,"children":4081},{"id":4080},"example-2-chaining-and-combining",[4082],{"type":35,"value":4083},"Example 2: Chaining and Combining",{"type":26,"tag":121,"props":4085,"children":4087},{"code":4086,"language":17,"meta":8,"className":123,"style":8},"import java.util.concurrent.CompletableFuture;\n\npublic class CompletableFutureCombineDemo {\n    public static void main(String[] args) {\n        CompletableFuture\u003CString> greeting = CompletableFuture.supplyAsync(() -> \"Hello\");\n        CompletableFuture\u003CString> name = CompletableFuture.supplyAsync(() -> \"World\");\n\n        CompletableFuture\u003CString> result = greeting.thenCombine(name, (g, n) -> g + \", \" + n);\n        System.out.println(result.join());\n    }\n}\n",[4088],{"type":26,"tag":15,"props":4089,"children":4090},{"__ignoreMap":8},[4091,4102,4109,4129,4168,4212,4257,4264,4326,4352,4359],{"type":26,"tag":130,"props":4092,"children":4093},{"class":132,"line":133},[4094,4098],{"type":26,"tag":130,"props":4095,"children":4096},{"style":143},[4097],{"type":35,"value":287},{"type":26,"tag":130,"props":4099,"children":4100},{"style":137},[4101],{"type":35,"value":3729},{"type":26,"tag":130,"props":4103,"children":4104},{"class":132,"line":176},[4105],{"type":26,"tag":130,"props":4106,"children":4107},{"emptyLinePlaceholder":298},[4108],{"type":35,"value":301},{"type":26,"tag":130,"props":4110,"children":4111},{"class":132,"line":205},[4112,4116,4120,4125],{"type":26,"tag":130,"props":4113,"children":4114},{"style":143},[4115],{"type":35,"value":3195},{"type":26,"tag":130,"props":4117,"children":4118},{"style":143},[4119],{"type":35,"value":3210},{"type":26,"tag":130,"props":4121,"children":4122},{"style":154},[4123],{"type":35,"value":4124}," CompletableFutureCombineDemo",{"type":26,"tag":130,"props":4126,"children":4127},{"style":137},[4128],{"type":35,"value":3285},{"type":26,"tag":130,"props":4130,"children":4131},{"class":132,"line":231},[4132,4136,4140,4144,4148,4152,4156,4160,4164],{"type":26,"tag":130,"props":4133,"children":4134},{"style":143},[4135],{"type":35,"value":3764},{"type":26,"tag":130,"props":4137,"children":4138},{"style":143},[4139],{"type":35,"value":3769},{"type":26,"tag":130,"props":4141,"children":4142},{"style":143},[4143],{"type":35,"value":3774},{"type":26,"tag":130,"props":4145,"children":4146},{"style":154},[4147],{"type":35,"value":3779},{"type":26,"tag":130,"props":4149,"children":4150},{"style":137},[4151],{"type":35,"value":162},{"type":26,"tag":130,"props":4153,"children":4154},{"style":143},[4155],{"type":35,"value":1426},{"type":26,"tag":130,"props":4157,"children":4158},{"style":137},[4159],{"type":35,"value":3792},{"type":26,"tag":130,"props":4161,"children":4162},{"style":3795},[4163],{"type":35,"value":3798},{"type":26,"tag":130,"props":4165,"children":4166},{"style":137},[4167],{"type":35,"value":3803},{"type":26,"tag":130,"props":4169,"children":4170},{"class":132,"line":364},[4171,4175,4179,4184,4188,4192,4196,4200,4204,4208],{"type":26,"tag":130,"props":4172,"children":4173},{"style":137},[4174],{"type":35,"value":3811},{"type":26,"tag":130,"props":4176,"children":4177},{"style":143},[4178],{"type":35,"value":1426},{"type":26,"tag":130,"props":4180,"children":4181},{"style":137},[4182],{"type":35,"value":4183},"> greeting ",{"type":26,"tag":130,"props":4185,"children":4186},{"style":143},[4187],{"type":35,"value":146},{"type":26,"tag":130,"props":4189,"children":4190},{"style":137},[4191],{"type":35,"value":3829},{"type":26,"tag":130,"props":4193,"children":4194},{"style":154},[4195],{"type":35,"value":3834},{"type":26,"tag":130,"props":4197,"children":4198},{"style":137},[4199],{"type":35,"value":3839},{"type":26,"tag":130,"props":4201,"children":4202},{"style":143},[4203],{"type":35,"value":1454},{"type":26,"tag":130,"props":4205,"children":4206},{"style":165},[4207],{"type":35,"value":2884},{"type":26,"tag":130,"props":4209,"children":4210},{"style":137},[4211],{"type":35,"value":173},{"type":26,"tag":130,"props":4213,"children":4214},{"class":132,"line":374},[4215,4219,4223,4228,4232,4236,4240,4244,4248,4253],{"type":26,"tag":130,"props":4216,"children":4217},{"style":137},[4218],{"type":35,"value":3811},{"type":26,"tag":130,"props":4220,"children":4221},{"style":143},[4222],{"type":35,"value":1426},{"type":26,"tag":130,"props":4224,"children":4225},{"style":137},[4226],{"type":35,"value":4227},"> name ",{"type":26,"tag":130,"props":4229,"children":4230},{"style":143},[4231],{"type":35,"value":146},{"type":26,"tag":130,"props":4233,"children":4234},{"style":137},[4235],{"type":35,"value":3829},{"type":26,"tag":130,"props":4237,"children":4238},{"style":154},[4239],{"type":35,"value":3834},{"type":26,"tag":130,"props":4241,"children":4242},{"style":137},[4243],{"type":35,"value":3839},{"type":26,"tag":130,"props":4245,"children":4246},{"style":143},[4247],{"type":35,"value":1454},{"type":26,"tag":130,"props":4249,"children":4250},{"style":165},[4251],{"type":35,"value":4252}," \"World\"",{"type":26,"tag":130,"props":4254,"children":4255},{"style":137},[4256],{"type":35,"value":173},{"type":26,"tag":130,"props":4258,"children":4259},{"class":132,"line":1353},[4260],{"type":26,"tag":130,"props":4261,"children":4262},{"emptyLinePlaceholder":298},[4263],{"type":35,"value":301},{"type":26,"tag":130,"props":4265,"children":4266},{"class":132,"line":1361},[4267,4271,4275,4280,4284,4289,4294,4299,4303,4308,4312,4317,4321],{"type":26,"tag":130,"props":4268,"children":4269},{"style":137},[4270],{"type":35,"value":3811},{"type":26,"tag":130,"props":4272,"children":4273},{"style":143},[4274],{"type":35,"value":1426},{"type":26,"tag":130,"props":4276,"children":4277},{"style":137},[4278],{"type":35,"value":4279},"> result ",{"type":26,"tag":130,"props":4281,"children":4282},{"style":143},[4283],{"type":35,"value":146},{"type":26,"tag":130,"props":4285,"children":4286},{"style":137},[4287],{"type":35,"value":4288}," greeting.",{"type":26,"tag":130,"props":4290,"children":4291},{"style":154},[4292],{"type":35,"value":4293},"thenCombine",{"type":26,"tag":130,"props":4295,"children":4296},{"style":137},[4297],{"type":35,"value":4298},"(name, (g, n) ",{"type":26,"tag":130,"props":4300,"children":4301},{"style":143},[4302],{"type":35,"value":1454},{"type":26,"tag":130,"props":4304,"children":4305},{"style":137},[4306],{"type":35,"value":4307}," g ",{"type":26,"tag":130,"props":4309,"children":4310},{"style":143},[4311],{"type":35,"value":3090},{"type":26,"tag":130,"props":4313,"children":4314},{"style":165},[4315],{"type":35,"value":4316}," \", \"",{"type":26,"tag":130,"props":4318,"children":4319},{"style":143},[4320],{"type":35,"value":1568},{"type":26,"tag":130,"props":4322,"children":4323},{"style":137},[4324],{"type":35,"value":4325}," n);\n",{"type":26,"tag":130,"props":4327,"children":4328},{"class":132,"line":1994},[4329,4334,4338,4343,4348],{"type":26,"tag":130,"props":4330,"children":4331},{"style":137},[4332],{"type":35,"value":4333},"        System.out.",{"type":26,"tag":130,"props":4335,"children":4336},{"style":154},[4337],{"type":35,"value":1554},{"type":26,"tag":130,"props":4339,"children":4340},{"style":137},[4341],{"type":35,"value":4342},"(result.",{"type":26,"tag":130,"props":4344,"children":4345},{"style":154},[4346],{"type":35,"value":4347},"join",{"type":26,"tag":130,"props":4349,"children":4350},{"style":137},[4351],{"type":35,"value":338},{"type":26,"tag":130,"props":4353,"children":4354},{"class":132,"line":2007},[4355],{"type":26,"tag":130,"props":4356,"children":4357},{"style":137},[4358],{"type":35,"value":3962},{"type":26,"tag":130,"props":4360,"children":4361},{"class":132,"line":2020},[4362],{"type":26,"tag":130,"props":4363,"children":4364},{"style":137},[4365],{"type":35,"value":380},{"type":26,"tag":31,"props":4367,"children":4368},{},[4369],{"type":26,"tag":994,"props":4370,"children":4371},{},[4372],{"type":35,"value":4069},{"type":26,"tag":121,"props":4374,"children":4376},{"code":4375},"Hello, World\n",[4377],{"type":26,"tag":15,"props":4378,"children":4379},{"__ignoreMap":8},[4380],{"type":35,"value":4375},{"type":26,"tag":1062,"props":4382,"children":4384},{"id":4383},"pros-and-cons-of-completablefuture",[4385],{"type":35,"value":4386},"Pros and Cons of CompletableFuture",{"type":26,"tag":31,"props":4388,"children":4389},{},[4390],{"type":26,"tag":994,"props":4391,"children":4392},{},[4393],{"type":35,"value":4394},"Pros:",{"type":26,"tag":896,"props":4396,"children":4397},{},[4398,4403,4408],{"type":26,"tag":54,"props":4399,"children":4400},{},[4401],{"type":35,"value":4402},"Native Java API, no dependencies",{"type":26,"tag":54,"props":4404,"children":4405},{},[4406],{"type":35,"value":4407},"Familiar to imperative developers",{"type":26,"tag":54,"props":4409,"children":4410},{},[4411],{"type":35,"value":4412},"Easy for linear async flows",{"type":26,"tag":31,"props":4414,"children":4415},{},[4416],{"type":26,"tag":994,"props":4417,"children":4418},{},[4419],{"type":35,"value":4420},"Cons:",{"type":26,"tag":896,"props":4422,"children":4423},{},[4424,4429,4434],{"type":26,"tag":54,"props":4425,"children":4426},{},[4427],{"type":35,"value":4428},"Limited operators compared to reactive libraries",{"type":26,"tag":54,"props":4430,"children":4431},{},[4432],{"type":35,"value":4433},"Complex error handling in larger flows",{"type":26,"tag":54,"props":4435,"children":4436},{},[4437],{"type":35,"value":4438},"Not suitable for high-throughput event streams",{"type":26,"tag":4440,"props":4441,"children":4442},"hr",{},[],{"type":26,"tag":38,"props":4444,"children":4446},{"id":4445},"_2-reactive-streams-declarative-and-event-driven",[4447],{"type":35,"value":4448},"2. Reactive Streams: Declarative and Event-Driven",{"type":26,"tag":31,"props":4450,"children":4451},{},[4452,4454,4459,4461,4467,4468,4474,4476,4481],{"type":35,"value":4453},"Reactive programming models async execution as a stream of data. With libraries like ",{"type":26,"tag":994,"props":4455,"children":4456},{},[4457],{"type":35,"value":4458},"Project Reactor",{"type":35,"value":4460}," (",{"type":26,"tag":15,"props":4462,"children":4464},{"className":4463},[],[4465],{"type":35,"value":4466},"Mono",{"type":35,"value":3233},{"type":26,"tag":15,"props":4469,"children":4471},{"className":4470},[],[4472],{"type":35,"value":4473},"Flux",{"type":35,"value":4475},") or ",{"type":26,"tag":994,"props":4477,"children":4478},{},[4479],{"type":35,"value":4480},"RxJava",{"type":35,"value":4482},", you can build pipelines to transform, filter, and combine async data.",{"type":26,"tag":1062,"props":4484,"children":4486},{"id":4485},"example-1-mono-single-async-value",[4487],{"type":35,"value":4488},"Example 1: Mono (Single Async Value)",{"type":26,"tag":121,"props":4490,"children":4492},{"code":4491,"language":17,"meta":8,"className":123,"style":8},"import reactor.core.publisher.Mono;\nimport java.time.Duration;\n\npublic class ReactorMonoExample {\n    public static void main(String[] args) {\n        Mono.just(\"Hello from Mono!\")\n            .delayElement(Duration.ofMillis(500))\n            .subscribe(System.out::println);\n\n        sleep(1000);\n    }\n\n    static void sleep(long millis) {\n        try { Thread.sleep(millis); } catch (InterruptedException e) { }\n    }\n}\n",[4493],{"type":26,"tag":15,"props":4494,"children":4495},{"__ignoreMap":8},[4496,4508,4520,4527,4547,4586,4612,4646,4670,4677,4696,4703,4710,4741,4776,4783],{"type":26,"tag":130,"props":4497,"children":4498},{"class":132,"line":133},[4499,4503],{"type":26,"tag":130,"props":4500,"children":4501},{"style":143},[4502],{"type":35,"value":287},{"type":26,"tag":130,"props":4504,"children":4505},{"style":137},[4506],{"type":35,"value":4507}," reactor.core.publisher.Mono;\n",{"type":26,"tag":130,"props":4509,"children":4510},{"class":132,"line":176},[4511,4515],{"type":26,"tag":130,"props":4512,"children":4513},{"style":143},[4514],{"type":35,"value":287},{"type":26,"tag":130,"props":4516,"children":4517},{"style":137},[4518],{"type":35,"value":4519}," java.time.Duration;\n",{"type":26,"tag":130,"props":4521,"children":4522},{"class":132,"line":205},[4523],{"type":26,"tag":130,"props":4524,"children":4525},{"emptyLinePlaceholder":298},[4526],{"type":35,"value":301},{"type":26,"tag":130,"props":4528,"children":4529},{"class":132,"line":231},[4530,4534,4538,4543],{"type":26,"tag":130,"props":4531,"children":4532},{"style":143},[4533],{"type":35,"value":3195},{"type":26,"tag":130,"props":4535,"children":4536},{"style":143},[4537],{"type":35,"value":3210},{"type":26,"tag":130,"props":4539,"children":4540},{"style":154},[4541],{"type":35,"value":4542}," ReactorMonoExample",{"type":26,"tag":130,"props":4544,"children":4545},{"style":137},[4546],{"type":35,"value":3285},{"type":26,"tag":130,"props":4548,"children":4549},{"class":132,"line":364},[4550,4554,4558,4562,4566,4570,4574,4578,4582],{"type":26,"tag":130,"props":4551,"children":4552},{"style":143},[4553],{"type":35,"value":3764},{"type":26,"tag":130,"props":4555,"children":4556},{"style":143},[4557],{"type":35,"value":3769},{"type":26,"tag":130,"props":4559,"children":4560},{"style":143},[4561],{"type":35,"value":3774},{"type":26,"tag":130,"props":4563,"children":4564},{"style":154},[4565],{"type":35,"value":3779},{"type":26,"tag":130,"props":4567,"children":4568},{"style":137},[4569],{"type":35,"value":162},{"type":26,"tag":130,"props":4571,"children":4572},{"style":143},[4573],{"type":35,"value":1426},{"type":26,"tag":130,"props":4575,"children":4576},{"style":137},[4577],{"type":35,"value":3792},{"type":26,"tag":130,"props":4579,"children":4580},{"style":3795},[4581],{"type":35,"value":3798},{"type":26,"tag":130,"props":4583,"children":4584},{"style":137},[4585],{"type":35,"value":3803},{"type":26,"tag":130,"props":4587,"children":4588},{"class":132,"line":374},[4589,4594,4599,4603,4608],{"type":26,"tag":130,"props":4590,"children":4591},{"style":137},[4592],{"type":35,"value":4593},"        Mono.",{"type":26,"tag":130,"props":4595,"children":4596},{"style":154},[4597],{"type":35,"value":4598},"just",{"type":26,"tag":130,"props":4600,"children":4601},{"style":137},[4602],{"type":35,"value":162},{"type":26,"tag":130,"props":4604,"children":4605},{"style":165},[4606],{"type":35,"value":4607},"\"Hello from Mono!\"",{"type":26,"tag":130,"props":4609,"children":4610},{"style":137},[4611],{"type":35,"value":1249},{"type":26,"tag":130,"props":4613,"children":4614},{"class":132,"line":1353},[4615,4620,4625,4629,4633,4637,4642],{"type":26,"tag":130,"props":4616,"children":4617},{"style":137},[4618],{"type":35,"value":4619},"            .",{"type":26,"tag":130,"props":4621,"children":4622},{"style":154},[4623],{"type":35,"value":4624},"delayElement",{"type":26,"tag":130,"props":4626,"children":4627},{"style":137},[4628],{"type":35,"value":1266},{"type":26,"tag":130,"props":4630,"children":4631},{"style":154},[4632],{"type":35,"value":1271},{"type":26,"tag":130,"props":4634,"children":4635},{"style":137},[4636],{"type":35,"value":162},{"type":26,"tag":130,"props":4638,"children":4639},{"style":194},[4640],{"type":35,"value":4641},"500",{"type":26,"tag":130,"props":4643,"children":4644},{"style":137},[4645],{"type":35,"value":1285},{"type":26,"tag":130,"props":4647,"children":4648},{"class":132,"line":1361},[4649,4653,4658,4662,4666],{"type":26,"tag":130,"props":4650,"children":4651},{"style":137},[4652],{"type":35,"value":4619},{"type":26,"tag":130,"props":4654,"children":4655},{"style":154},[4656],{"type":35,"value":4657},"subscribe",{"type":26,"tag":130,"props":4659,"children":4660},{"style":137},[4661],{"type":35,"value":3917},{"type":26,"tag":130,"props":4663,"children":4664},{"style":143},[4665],{"type":35,"value":3922},{"type":26,"tag":130,"props":4667,"children":4668},{"style":137},[4669],{"type":35,"value":3927},{"type":26,"tag":130,"props":4671,"children":4672},{"class":132,"line":1994},[4673],{"type":26,"tag":130,"props":4674,"children":4675},{"emptyLinePlaceholder":298},[4676],{"type":35,"value":301},{"type":26,"tag":130,"props":4678,"children":4679},{"class":132,"line":2007},[4680,4684,4688,4692],{"type":26,"tag":130,"props":4681,"children":4682},{"style":154},[4683],{"type":35,"value":3935},{"type":26,"tag":130,"props":4685,"children":4686},{"style":137},[4687],{"type":35,"value":162},{"type":26,"tag":130,"props":4689,"children":4690},{"style":194},[4691],{"type":35,"value":1280},{"type":26,"tag":130,"props":4693,"children":4694},{"style":137},[4695],{"type":35,"value":173},{"type":26,"tag":130,"props":4697,"children":4698},{"class":132,"line":2020},[4699],{"type":26,"tag":130,"props":4700,"children":4701},{"style":137},[4702],{"type":35,"value":3962},{"type":26,"tag":130,"props":4704,"children":4705},{"class":132,"line":2038},[4706],{"type":26,"tag":130,"props":4707,"children":4708},{"emptyLinePlaceholder":298},[4709],{"type":35,"value":301},{"type":26,"tag":130,"props":4711,"children":4712},{"class":132,"line":2046},[4713,4717,4721,4725,4729,4733,4737],{"type":26,"tag":130,"props":4714,"children":4715},{"style":143},[4716],{"type":35,"value":3977},{"type":26,"tag":130,"props":4718,"children":4719},{"style":143},[4720],{"type":35,"value":3774},{"type":26,"tag":130,"props":4722,"children":4723},{"style":154},[4724],{"type":35,"value":3986},{"type":26,"tag":130,"props":4726,"children":4727},{"style":137},[4728],{"type":35,"value":162},{"type":26,"tag":130,"props":4730,"children":4731},{"style":143},[4732],{"type":35,"value":3995},{"type":26,"tag":130,"props":4734,"children":4735},{"style":3795},[4736],{"type":35,"value":4000},{"type":26,"tag":130,"props":4738,"children":4739},{"style":137},[4740],{"type":35,"value":3803},{"type":26,"tag":130,"props":4742,"children":4743},{"class":132,"line":2059},[4744,4748,4752,4756,4760,4764,4768,4772],{"type":26,"tag":130,"props":4745,"children":4746},{"style":143},[4747],{"type":35,"value":4012},{"type":26,"tag":130,"props":4749,"children":4750},{"style":137},[4751],{"type":35,"value":4017},{"type":26,"tag":130,"props":4753,"children":4754},{"style":154},[4755],{"type":35,"value":4022},{"type":26,"tag":130,"props":4757,"children":4758},{"style":137},[4759],{"type":35,"value":4027},{"type":26,"tag":130,"props":4761,"children":4762},{"style":143},[4763],{"type":35,"value":4032},{"type":26,"tag":130,"props":4765,"children":4766},{"style":137},[4767],{"type":35,"value":4037},{"type":26,"tag":130,"props":4769,"children":4770},{"style":3795},[4771],{"type":35,"value":4042},{"type":26,"tag":130,"props":4773,"children":4774},{"style":137},[4775],{"type":35,"value":4047},{"type":26,"tag":130,"props":4777,"children":4778},{"class":132,"line":2082},[4779],{"type":26,"tag":130,"props":4780,"children":4781},{"style":137},[4782],{"type":35,"value":3962},{"type":26,"tag":130,"props":4784,"children":4785},{"class":132,"line":2103},[4786],{"type":26,"tag":130,"props":4787,"children":4788},{"style":137},[4789],{"type":35,"value":380},{"type":26,"tag":31,"props":4791,"children":4792},{},[4793],{"type":26,"tag":994,"props":4794,"children":4795},{},[4796],{"type":35,"value":4069},{"type":26,"tag":121,"props":4798,"children":4800},{"code":4799},"Hello from Mono!\n",[4801],{"type":26,"tag":15,"props":4802,"children":4803},{"__ignoreMap":8},[4804],{"type":35,"value":4799},{"type":26,"tag":1062,"props":4806,"children":4808},{"id":4807},"example-2-flux-multiple-async-events",[4809],{"type":35,"value":4810},"Example 2: Flux (Multiple Async Events)",{"type":26,"tag":121,"props":4812,"children":4814},{"code":4813,"language":17,"meta":8,"className":123,"style":8},"import reactor.core.publisher.Flux;\nimport java.time.Duration;\n\npublic class ReactorFluxExample {\n    public static void main(String[] args) {\n        Flux.interval(Duration.ofMillis(300))\n            .take(5)\n            .map(i -> \"Tick \" + i)\n            .subscribe(System.out::println);\n\n        sleep(2000);\n    }\n\n    static void sleep(long millis) {\n        try { Thread.sleep(millis); } catch (InterruptedException e) { }\n    }\n}\n",[4815],{"type":26,"tag":15,"props":4816,"children":4817},{"__ignoreMap":8},[4818,4830,4841,4848,4868,4907,4941,4965,4999,5022,5029,5049,5056,5063,5094,5129,5136],{"type":26,"tag":130,"props":4819,"children":4820},{"class":132,"line":133},[4821,4825],{"type":26,"tag":130,"props":4822,"children":4823},{"style":143},[4824],{"type":35,"value":287},{"type":26,"tag":130,"props":4826,"children":4827},{"style":137},[4828],{"type":35,"value":4829}," reactor.core.publisher.Flux;\n",{"type":26,"tag":130,"props":4831,"children":4832},{"class":132,"line":176},[4833,4837],{"type":26,"tag":130,"props":4834,"children":4835},{"style":143},[4836],{"type":35,"value":287},{"type":26,"tag":130,"props":4838,"children":4839},{"style":137},[4840],{"type":35,"value":4519},{"type":26,"tag":130,"props":4842,"children":4843},{"class":132,"line":205},[4844],{"type":26,"tag":130,"props":4845,"children":4846},{"emptyLinePlaceholder":298},[4847],{"type":35,"value":301},{"type":26,"tag":130,"props":4849,"children":4850},{"class":132,"line":231},[4851,4855,4859,4864],{"type":26,"tag":130,"props":4852,"children":4853},{"style":143},[4854],{"type":35,"value":3195},{"type":26,"tag":130,"props":4856,"children":4857},{"style":143},[4858],{"type":35,"value":3210},{"type":26,"tag":130,"props":4860,"children":4861},{"style":154},[4862],{"type":35,"value":4863}," ReactorFluxExample",{"type":26,"tag":130,"props":4865,"children":4866},{"style":137},[4867],{"type":35,"value":3285},{"type":26,"tag":130,"props":4869,"children":4870},{"class":132,"line":364},[4871,4875,4879,4883,4887,4891,4895,4899,4903],{"type":26,"tag":130,"props":4872,"children":4873},{"style":143},[4874],{"type":35,"value":3764},{"type":26,"tag":130,"props":4876,"children":4877},{"style":143},[4878],{"type":35,"value":3769},{"type":26,"tag":130,"props":4880,"children":4881},{"style":143},[4882],{"type":35,"value":3774},{"type":26,"tag":130,"props":4884,"children":4885},{"style":154},[4886],{"type":35,"value":3779},{"type":26,"tag":130,"props":4888,"children":4889},{"style":137},[4890],{"type":35,"value":162},{"type":26,"tag":130,"props":4892,"children":4893},{"style":143},[4894],{"type":35,"value":1426},{"type":26,"tag":130,"props":4896,"children":4897},{"style":137},[4898],{"type":35,"value":3792},{"type":26,"tag":130,"props":4900,"children":4901},{"style":3795},[4902],{"type":35,"value":3798},{"type":26,"tag":130,"props":4904,"children":4905},{"style":137},[4906],{"type":35,"value":3803},{"type":26,"tag":130,"props":4908,"children":4909},{"class":132,"line":374},[4910,4915,4920,4924,4928,4932,4937],{"type":26,"tag":130,"props":4911,"children":4912},{"style":137},[4913],{"type":35,"value":4914},"        Flux.",{"type":26,"tag":130,"props":4916,"children":4917},{"style":154},[4918],{"type":35,"value":4919},"interval",{"type":26,"tag":130,"props":4921,"children":4922},{"style":137},[4923],{"type":35,"value":1266},{"type":26,"tag":130,"props":4925,"children":4926},{"style":154},[4927],{"type":35,"value":1271},{"type":26,"tag":130,"props":4929,"children":4930},{"style":137},[4931],{"type":35,"value":162},{"type":26,"tag":130,"props":4933,"children":4934},{"style":194},[4935],{"type":35,"value":4936},"300",{"type":26,"tag":130,"props":4938,"children":4939},{"style":137},[4940],{"type":35,"value":1285},{"type":26,"tag":130,"props":4942,"children":4943},{"class":132,"line":1353},[4944,4948,4953,4957,4961],{"type":26,"tag":130,"props":4945,"children":4946},{"style":137},[4947],{"type":35,"value":4619},{"type":26,"tag":130,"props":4949,"children":4950},{"style":154},[4951],{"type":35,"value":4952},"take",{"type":26,"tag":130,"props":4954,"children":4955},{"style":137},[4956],{"type":35,"value":162},{"type":26,"tag":130,"props":4958,"children":4959},{"style":194},[4960],{"type":35,"value":1330},{"type":26,"tag":130,"props":4962,"children":4963},{"style":137},[4964],{"type":35,"value":1249},{"type":26,"tag":130,"props":4966,"children":4967},{"class":132,"line":1361},[4968,4972,4977,4981,4985,4990,4994],{"type":26,"tag":130,"props":4969,"children":4970},{"style":137},[4971],{"type":35,"value":4619},{"type":26,"tag":130,"props":4973,"children":4974},{"style":154},[4975],{"type":35,"value":4976},"map",{"type":26,"tag":130,"props":4978,"children":4979},{"style":137},[4980],{"type":35,"value":3085},{"type":26,"tag":130,"props":4982,"children":4983},{"style":143},[4984],{"type":35,"value":1454},{"type":26,"tag":130,"props":4986,"children":4987},{"style":165},[4988],{"type":35,"value":4989}," \"Tick \"",{"type":26,"tag":130,"props":4991,"children":4992},{"style":143},[4993],{"type":35,"value":1568},{"type":26,"tag":130,"props":4995,"children":4996},{"style":137},[4997],{"type":35,"value":4998}," i)\n",{"type":26,"tag":130,"props":5000,"children":5001},{"class":132,"line":1994},[5002,5006,5010,5014,5018],{"type":26,"tag":130,"props":5003,"children":5004},{"style":137},[5005],{"type":35,"value":4619},{"type":26,"tag":130,"props":5007,"children":5008},{"style":154},[5009],{"type":35,"value":4657},{"type":26,"tag":130,"props":5011,"children":5012},{"style":137},[5013],{"type":35,"value":3917},{"type":26,"tag":130,"props":5015,"children":5016},{"style":143},[5017],{"type":35,"value":3922},{"type":26,"tag":130,"props":5019,"children":5020},{"style":137},[5021],{"type":35,"value":3927},{"type":26,"tag":130,"props":5023,"children":5024},{"class":132,"line":2007},[5025],{"type":26,"tag":130,"props":5026,"children":5027},{"emptyLinePlaceholder":298},[5028],{"type":35,"value":301},{"type":26,"tag":130,"props":5030,"children":5031},{"class":132,"line":2020},[5032,5036,5040,5045],{"type":26,"tag":130,"props":5033,"children":5034},{"style":154},[5035],{"type":35,"value":3935},{"type":26,"tag":130,"props":5037,"children":5038},{"style":137},[5039],{"type":35,"value":162},{"type":26,"tag":130,"props":5041,"children":5042},{"style":194},[5043],{"type":35,"value":5044},"2000",{"type":26,"tag":130,"props":5046,"children":5047},{"style":137},[5048],{"type":35,"value":173},{"type":26,"tag":130,"props":5050,"children":5051},{"class":132,"line":2038},[5052],{"type":26,"tag":130,"props":5053,"children":5054},{"style":137},[5055],{"type":35,"value":3962},{"type":26,"tag":130,"props":5057,"children":5058},{"class":132,"line":2046},[5059],{"type":26,"tag":130,"props":5060,"children":5061},{"emptyLinePlaceholder":298},[5062],{"type":35,"value":301},{"type":26,"tag":130,"props":5064,"children":5065},{"class":132,"line":2059},[5066,5070,5074,5078,5082,5086,5090],{"type":26,"tag":130,"props":5067,"children":5068},{"style":143},[5069],{"type":35,"value":3977},{"type":26,"tag":130,"props":5071,"children":5072},{"style":143},[5073],{"type":35,"value":3774},{"type":26,"tag":130,"props":5075,"children":5076},{"style":154},[5077],{"type":35,"value":3986},{"type":26,"tag":130,"props":5079,"children":5080},{"style":137},[5081],{"type":35,"value":162},{"type":26,"tag":130,"props":5083,"children":5084},{"style":143},[5085],{"type":35,"value":3995},{"type":26,"tag":130,"props":5087,"children":5088},{"style":3795},[5089],{"type":35,"value":4000},{"type":26,"tag":130,"props":5091,"children":5092},{"style":137},[5093],{"type":35,"value":3803},{"type":26,"tag":130,"props":5095,"children":5096},{"class":132,"line":2082},[5097,5101,5105,5109,5113,5117,5121,5125],{"type":26,"tag":130,"props":5098,"children":5099},{"style":143},[5100],{"type":35,"value":4012},{"type":26,"tag":130,"props":5102,"children":5103},{"style":137},[5104],{"type":35,"value":4017},{"type":26,"tag":130,"props":5106,"children":5107},{"style":154},[5108],{"type":35,"value":4022},{"type":26,"tag":130,"props":5110,"children":5111},{"style":137},[5112],{"type":35,"value":4027},{"type":26,"tag":130,"props":5114,"children":5115},{"style":143},[5116],{"type":35,"value":4032},{"type":26,"tag":130,"props":5118,"children":5119},{"style":137},[5120],{"type":35,"value":4037},{"type":26,"tag":130,"props":5122,"children":5123},{"style":3795},[5124],{"type":35,"value":4042},{"type":26,"tag":130,"props":5126,"children":5127},{"style":137},[5128],{"type":35,"value":4047},{"type":26,"tag":130,"props":5130,"children":5131},{"class":132,"line":2103},[5132],{"type":26,"tag":130,"props":5133,"children":5134},{"style":137},[5135],{"type":35,"value":3962},{"type":26,"tag":130,"props":5137,"children":5138},{"class":132,"line":2121},[5139],{"type":26,"tag":130,"props":5140,"children":5141},{"style":137},[5142],{"type":35,"value":380},{"type":26,"tag":31,"props":5144,"children":5145},{},[5146],{"type":26,"tag":994,"props":5147,"children":5148},{},[5149],{"type":35,"value":4069},{"type":26,"tag":121,"props":5151,"children":5153},{"code":5152},"Tick 0\nTick 1\nTick 2\nTick 3\nTick 4\n",[5154],{"type":26,"tag":15,"props":5155,"children":5156},{"__ignoreMap":8},[5157],{"type":35,"value":5152},{"type":26,"tag":1062,"props":5159,"children":5161},{"id":5160},"pros-and-cons-of-reactive-streams",[5162],{"type":35,"value":5163},"Pros and Cons of Reactive Streams",{"type":26,"tag":31,"props":5165,"children":5166},{},[5167],{"type":26,"tag":994,"props":5168,"children":5169},{},[5170],{"type":35,"value":4394},{"type":26,"tag":896,"props":5172,"children":5173},{},[5174,5179,5184],{"type":26,"tag":54,"props":5175,"children":5176},{},[5177],{"type":35,"value":5178},"Rich operator set for complex flows",{"type":26,"tag":54,"props":5180,"children":5181},{},[5182],{"type":35,"value":5183},"Built-in backpressure handling",{"type":26,"tag":54,"props":5185,"children":5186},{},[5187],{"type":35,"value":5188},"Ideal for data streams and event-driven apps",{"type":26,"tag":31,"props":5190,"children":5191},{},[5192],{"type":26,"tag":994,"props":5193,"children":5194},{},[5195],{"type":35,"value":4420},{"type":26,"tag":896,"props":5197,"children":5198},{},[5199,5204,5209],{"type":26,"tag":54,"props":5200,"children":5201},{},[5202],{"type":35,"value":5203},"Requires learning new paradigm",{"type":26,"tag":54,"props":5205,"children":5206},{},[5207],{"type":35,"value":5208},"Can be overkill for simple use cases",{"type":26,"tag":54,"props":5210,"children":5211},{},[5212],{"type":35,"value":5213},"More dependencies (Reactor, RxJava)",{"type":26,"tag":4440,"props":5215,"children":5216},{},[],{"type":26,"tag":38,"props":5218,"children":5220},{"id":5219},"_3-when-to-use-each",[5221],{"type":35,"value":5222},"3. When to Use Each?",{"type":26,"tag":5224,"props":5225,"children":5226},"table",{},[5227,5249],{"type":26,"tag":5228,"props":5229,"children":5230},"thead",{},[5231],{"type":26,"tag":5232,"props":5233,"children":5234},"tr",{},[5235,5241,5245],{"type":26,"tag":5236,"props":5237,"children":5238},"th",{},[5239],{"type":35,"value":5240},"Use Case",{"type":26,"tag":5236,"props":5242,"children":5243},{},[5244],{"type":35,"value":3680},{"type":26,"tag":5236,"props":5246,"children":5247},{},[5248],{"type":35,"value":3686},{"type":26,"tag":5250,"props":5251,"children":5252},"tbody",{},[5253,5272,5288,5304,5320,5336],{"type":26,"tag":5232,"props":5254,"children":5255},{},[5256,5262,5267],{"type":26,"tag":5257,"props":5258,"children":5259},"td",{},[5260],{"type":35,"value":5261},"Simple async call",{"type":26,"tag":5257,"props":5263,"children":5264},{},[5265],{"type":35,"value":5266},"✅",{"type":26,"tag":5257,"props":5268,"children":5269},{},[5270],{"type":35,"value":5271},"❌",{"type":26,"tag":5232,"props":5273,"children":5274},{},[5275,5280,5284],{"type":26,"tag":5257,"props":5276,"children":5277},{},[5278],{"type":35,"value":5279},"API call + transform",{"type":26,"tag":5257,"props":5281,"children":5282},{},[5283],{"type":35,"value":5266},{"type":26,"tag":5257,"props":5285,"children":5286},{},[5287],{"type":35,"value":5266},{"type":26,"tag":5232,"props":5289,"children":5290},{},[5291,5296,5300],{"type":26,"tag":5257,"props":5292,"children":5293},{},[5294],{"type":35,"value":5295},"Data pipeline (streaming)",{"type":26,"tag":5257,"props":5297,"children":5298},{},[5299],{"type":35,"value":5271},{"type":26,"tag":5257,"props":5301,"children":5302},{},[5303],{"type":35,"value":5266},{"type":26,"tag":5232,"props":5305,"children":5306},{},[5307,5312,5316],{"type":26,"tag":5257,"props":5308,"children":5309},{},[5310],{"type":35,"value":5311},"Reactive UI/backend",{"type":26,"tag":5257,"props":5313,"children":5314},{},[5315],{"type":35,"value":5271},{"type":26,"tag":5257,"props":5317,"children":5318},{},[5319],{"type":35,"value":5266},{"type":26,"tag":5232,"props":5321,"children":5322},{},[5323,5328,5332],{"type":26,"tag":5257,"props":5324,"children":5325},{},[5326],{"type":35,"value":5327},"Minimal dependencies",{"type":26,"tag":5257,"props":5329,"children":5330},{},[5331],{"type":35,"value":5266},{"type":26,"tag":5257,"props":5333,"children":5334},{},[5335],{"type":35,"value":5271},{"type":26,"tag":5232,"props":5337,"children":5338},{},[5339,5344,5348],{"type":26,"tag":5257,"props":5340,"children":5341},{},[5342],{"type":35,"value":5343},"Advanced composition",{"type":26,"tag":5257,"props":5345,"children":5346},{},[5347],{"type":35,"value":5271},{"type":26,"tag":5257,"props":5349,"children":5350},{},[5351],{"type":35,"value":5266},{"type":26,"tag":4440,"props":5353,"children":5354},{},[],{"type":26,"tag":38,"props":5356,"children":5357},{"id":879},[5358],{"type":35,"value":882},{"type":26,"tag":31,"props":5360,"children":5361},{},[5362,5364,5369,5371,5376],{"type":35,"value":5363},"Both ",{"type":26,"tag":15,"props":5365,"children":5367},{"className":5366},[],[5368],{"type":35,"value":3680},{"type":35,"value":5370}," and Reactive Streams serve asynchronous needs, but they excel in different areas. For straightforward async calls, ",{"type":26,"tag":15,"props":5372,"children":5374},{"className":5373},[],[5375],{"type":35,"value":3680},{"type":35,"value":5377}," is often enough. For complex, event-driven, and high-throughput systems, reactive programming shines.",{"type":26,"tag":31,"props":5379,"children":5380},{},[5381],{"type":35,"value":5382},"By mastering both, you’ll be ready to choose the right tool for every concurrency challenge in modern Java applications.",{"type":26,"tag":889,"props":5384,"children":5385},{"id":891},[5386],{"type":35,"value":894},{"type":26,"tag":896,"props":5388,"children":5389},{},[5390,5400,5410],{"type":26,"tag":54,"props":5391,"children":5392},{},[5393],{"type":26,"tag":903,"props":5394,"children":5397},{"href":5395,"rel":5396},"https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletableFuture.html",[907],[5398],{"type":35,"value":5399},"CompletableFuture Javadoc",{"type":26,"tag":54,"props":5401,"children":5402},{},[5403],{"type":26,"tag":903,"props":5404,"children":5407},{"href":5405,"rel":5406},"https://projectreactor.io/docs",[907],[5408],{"type":35,"value":5409},"Project Reactor Documentation",{"type":26,"tag":54,"props":5411,"children":5412},{},[5413],{"type":26,"tag":903,"props":5414,"children":5417},{"href":5415,"rel":5416},"https://www.reactivemanifesto.org/",[907],[5418],{"type":35,"value":5419},"Reactive Manifesto",{"type":26,"tag":932,"props":5421,"children":5422},{},[5423],{"type":35,"value":936},{"title":8,"searchDepth":176,"depth":176,"links":5425},[5426,5431,5436,5437],{"id":3691,"depth":176,"text":3694,"children":5427},[5428,5429,5430],{"id":3707,"depth":205,"text":3710},{"id":4080,"depth":205,"text":4083},{"id":4383,"depth":205,"text":4386},{"id":4445,"depth":176,"text":4448,"children":5432},[5433,5434,5435],{"id":4485,"depth":205,"text":4488},{"id":4807,"depth":205,"text":4810},{"id":5160,"depth":205,"text":5163},{"id":5219,"depth":176,"text":5222},{"id":879,"depth":176,"text":882},"content:posts:async-java-completable-vs-reactive.md","posts/async-java-completable-vs-reactive.md","posts/async-java-completable-vs-reactive",{"_path":5442,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":5443,"description":5444,"date":5445,"layout":12,"subtitle":5446,"image":5447,"optimized_image":5447,"category":15,"tags":5448,"author":21,"paginate":7,"body":5450,"_type":949,"_id":6687,"_source":951,"_file":6688,"_stem":6689,"_extension":954},"/posts/mastering-concurrency","Mastering Concurrency in Java: Threads, Executors, and Virtual Threads","Exploring Java’s concurrency model with detailed insights into Threads, ExecutorService, and Virtual Threads from Project Loom.","2024-03-15T11:00:00.000Z","A Deep Dive into Java’s Multithreading and Parallel Computing","/assets/img/uploads/java-concurrency.png",[15,17,3664,5449],"multithreading",{"type":23,"children":5451,"toc":6670},[5452,5460,5466,5471,5524,5537,5543,5571,5808,5814,5847,5852,5858,5878,5884,5889,6181,6187,6234,6240,6258,6264,6269,6275,6308,6313,6577,6583,6601,6605,6610,6615,6619,6661,6666],{"type":26,"tag":27,"props":5453,"children":5454},{},[5455],{"type":26,"tag":31,"props":5456,"children":5457},{},[5458],{"type":35,"value":5459},"Java's concurrency model is a critical component for building scalable and efficient applications. From classic Thread management to modern ExecutorService and the revolutionary Virtual Threads in Project Loom, mastering Java’s concurrency tools is essential for high-performance development.",{"type":26,"tag":38,"props":5461,"children":5463},{"id":5462},"understanding-javas-concurrency-model",[5464],{"type":35,"value":5465},"Understanding Java’s Concurrency Model",{"type":26,"tag":31,"props":5467,"children":5468},{},[5469],{"type":35,"value":5470},"Concurrency in Java enables applications to perform multiple tasks simultaneously, improving throughput and responsiveness. Java provides several concurrency primitives:",{"type":26,"tag":896,"props":5472,"children":5473},{},[5474,5484,5494,5504,5514],{"type":26,"tag":54,"props":5475,"children":5476},{},[5477,5482],{"type":26,"tag":994,"props":5478,"children":5479},{},[5480],{"type":35,"value":5481},"Threads",{"type":35,"value":5483},": The fundamental unit of execution, allowing tasks to run in parallel.",{"type":26,"tag":54,"props":5485,"children":5486},{},[5487,5492],{"type":26,"tag":994,"props":5488,"children":5489},{},[5490],{"type":35,"value":5491},"Executors",{"type":35,"value":5493},": High-level abstraction for managing thread pools and task execution.",{"type":26,"tag":54,"props":5495,"children":5496},{},[5497,5502],{"type":26,"tag":994,"props":5498,"children":5499},{},[5500],{"type":35,"value":5501},"Virtual Threads",{"type":35,"value":5503},": Lightweight, memory-efficient threads introduced in Java 21 for massive scalability.",{"type":26,"tag":54,"props":5505,"children":5506},{},[5507,5512],{"type":26,"tag":994,"props":5508,"children":5509},{},[5510],{"type":35,"value":5511},"Fork/Join Framework",{"type":35,"value":5513},": Designed for divide-and-conquer algorithms using parallel task execution.",{"type":26,"tag":54,"props":5515,"children":5516},{},[5517,5522],{"type":26,"tag":994,"props":5518,"children":5519},{},[5520],{"type":35,"value":5521},"Reactive Programming",{"type":35,"value":5523},": Asynchronous, non-blocking programming using event streams.",{"type":26,"tag":31,"props":5525,"children":5526},{},[5527,5529,5535],{"type":35,"value":5528},"Let's now take a deeper look at three major building blocks of concurrent programming in Java: classic threads, the ",{"type":26,"tag":15,"props":5530,"children":5532},{"className":5531},[],[5533],{"type":35,"value":5534},"ExecutorService",{"type":35,"value":5536},", and the new virtual threads.",{"type":26,"tag":38,"props":5538,"children":5540},{"id":5539},"classic-approach-java-threads",[5541],{"type":35,"value":5542},"Classic Approach: Java Threads",{"type":26,"tag":31,"props":5544,"children":5545},{},[5546,5548,5554,5556,5561,5563,5569],{"type":35,"value":5547},"The most basic unit of concurrency in Java is the ",{"type":26,"tag":15,"props":5549,"children":5551},{"className":5550},[],[5552],{"type":35,"value":5553},"Thread",{"type":35,"value":5555},". You can extend the ",{"type":26,"tag":15,"props":5557,"children":5559},{"className":5558},[],[5560],{"type":35,"value":5553},{"type":35,"value":5562}," class or implement the ",{"type":26,"tag":15,"props":5564,"children":5566},{"className":5565},[],[5567],{"type":35,"value":5568},"Runnable",{"type":35,"value":5570}," interface to define concurrent tasks.",{"type":26,"tag":121,"props":5572,"children":5574},{"className":123,"code":5573,"language":17,"meta":8,"style":8},"class SimpleThreadExample extends Thread {\n    public void run() {\n        System.out.println(\"Thread running: \" + Thread.currentThread().getName());\n    }\n}\n\npublic class ThreadDemo {\n    public static void main(String[] args) {\n        SimpleThreadExample thread = new SimpleThreadExample();\n        thread.start();\n    }\n}\n",[5575],{"type":26,"tag":15,"props":5576,"children":5577},{"__ignoreMap":8},[5578,5604,5625,5673,5680,5687,5694,5714,5753,5777,5794,5801],{"type":26,"tag":130,"props":5579,"children":5580},{"class":132,"line":133},[5581,5586,5591,5595,5600],{"type":26,"tag":130,"props":5582,"children":5583},{"style":143},[5584],{"type":35,"value":5585},"class",{"type":26,"tag":130,"props":5587,"children":5588},{"style":154},[5589],{"type":35,"value":5590}," SimpleThreadExample",{"type":26,"tag":130,"props":5592,"children":5593},{"style":143},[5594],{"type":35,"value":3275},{"type":26,"tag":130,"props":5596,"children":5597},{"style":154},[5598],{"type":35,"value":5599}," Thread",{"type":26,"tag":130,"props":5601,"children":5602},{"style":137},[5603],{"type":35,"value":3285},{"type":26,"tag":130,"props":5605,"children":5606},{"class":132,"line":176},[5607,5611,5615,5620],{"type":26,"tag":130,"props":5608,"children":5609},{"style":143},[5610],{"type":35,"value":3764},{"type":26,"tag":130,"props":5612,"children":5613},{"style":143},[5614],{"type":35,"value":3774},{"type":26,"tag":130,"props":5616,"children":5617},{"style":154},[5618],{"type":35,"value":5619}," run",{"type":26,"tag":130,"props":5621,"children":5622},{"style":137},[5623],{"type":35,"value":5624},"() {\n",{"type":26,"tag":130,"props":5626,"children":5627},{"class":132,"line":205},[5628,5632,5636,5640,5645,5649,5654,5659,5664,5669],{"type":26,"tag":130,"props":5629,"children":5630},{"style":137},[5631],{"type":35,"value":4333},{"type":26,"tag":130,"props":5633,"children":5634},{"style":154},[5635],{"type":35,"value":1554},{"type":26,"tag":130,"props":5637,"children":5638},{"style":137},[5639],{"type":35,"value":162},{"type":26,"tag":130,"props":5641,"children":5642},{"style":165},[5643],{"type":35,"value":5644},"\"Thread running: \"",{"type":26,"tag":130,"props":5646,"children":5647},{"style":143},[5648],{"type":35,"value":1568},{"type":26,"tag":130,"props":5650,"children":5651},{"style":137},[5652],{"type":35,"value":5653}," Thread.",{"type":26,"tag":130,"props":5655,"children":5656},{"style":154},[5657],{"type":35,"value":5658},"currentThread",{"type":26,"tag":130,"props":5660,"children":5661},{"style":137},[5662],{"type":35,"value":5663},"().",{"type":26,"tag":130,"props":5665,"children":5666},{"style":154},[5667],{"type":35,"value":5668},"getName",{"type":26,"tag":130,"props":5670,"children":5671},{"style":137},[5672],{"type":35,"value":338},{"type":26,"tag":130,"props":5674,"children":5675},{"class":132,"line":231},[5676],{"type":26,"tag":130,"props":5677,"children":5678},{"style":137},[5679],{"type":35,"value":3962},{"type":26,"tag":130,"props":5681,"children":5682},{"class":132,"line":364},[5683],{"type":26,"tag":130,"props":5684,"children":5685},{"style":137},[5686],{"type":35,"value":380},{"type":26,"tag":130,"props":5688,"children":5689},{"class":132,"line":374},[5690],{"type":26,"tag":130,"props":5691,"children":5692},{"emptyLinePlaceholder":298},[5693],{"type":35,"value":301},{"type":26,"tag":130,"props":5695,"children":5696},{"class":132,"line":1353},[5697,5701,5705,5710],{"type":26,"tag":130,"props":5698,"children":5699},{"style":143},[5700],{"type":35,"value":3195},{"type":26,"tag":130,"props":5702,"children":5703},{"style":143},[5704],{"type":35,"value":3210},{"type":26,"tag":130,"props":5706,"children":5707},{"style":154},[5708],{"type":35,"value":5709}," ThreadDemo",{"type":26,"tag":130,"props":5711,"children":5712},{"style":137},[5713],{"type":35,"value":3285},{"type":26,"tag":130,"props":5715,"children":5716},{"class":132,"line":1361},[5717,5721,5725,5729,5733,5737,5741,5745,5749],{"type":26,"tag":130,"props":5718,"children":5719},{"style":143},[5720],{"type":35,"value":3764},{"type":26,"tag":130,"props":5722,"children":5723},{"style":143},[5724],{"type":35,"value":3769},{"type":26,"tag":130,"props":5726,"children":5727},{"style":143},[5728],{"type":35,"value":3774},{"type":26,"tag":130,"props":5730,"children":5731},{"style":154},[5732],{"type":35,"value":3779},{"type":26,"tag":130,"props":5734,"children":5735},{"style":137},[5736],{"type":35,"value":162},{"type":26,"tag":130,"props":5738,"children":5739},{"style":143},[5740],{"type":35,"value":1426},{"type":26,"tag":130,"props":5742,"children":5743},{"style":137},[5744],{"type":35,"value":3792},{"type":26,"tag":130,"props":5746,"children":5747},{"style":3795},[5748],{"type":35,"value":3798},{"type":26,"tag":130,"props":5750,"children":5751},{"style":137},[5752],{"type":35,"value":3803},{"type":26,"tag":130,"props":5754,"children":5755},{"class":132,"line":1994},[5756,5761,5765,5769,5773],{"type":26,"tag":130,"props":5757,"children":5758},{"style":137},[5759],{"type":35,"value":5760},"        SimpleThreadExample thread ",{"type":26,"tag":130,"props":5762,"children":5763},{"style":143},[5764],{"type":35,"value":146},{"type":26,"tag":130,"props":5766,"children":5767},{"style":143},[5768],{"type":35,"value":627},{"type":26,"tag":130,"props":5770,"children":5771},{"style":154},[5772],{"type":35,"value":5590},{"type":26,"tag":130,"props":5774,"children":5775},{"style":137},[5776],{"type":35,"value":256},{"type":26,"tag":130,"props":5778,"children":5779},{"class":132,"line":2007},[5780,5785,5790],{"type":26,"tag":130,"props":5781,"children":5782},{"style":137},[5783],{"type":35,"value":5784},"        thread.",{"type":26,"tag":130,"props":5786,"children":5787},{"style":154},[5788],{"type":35,"value":5789},"start",{"type":26,"tag":130,"props":5791,"children":5792},{"style":137},[5793],{"type":35,"value":256},{"type":26,"tag":130,"props":5795,"children":5796},{"class":132,"line":2020},[5797],{"type":26,"tag":130,"props":5798,"children":5799},{"style":137},[5800],{"type":35,"value":3962},{"type":26,"tag":130,"props":5802,"children":5803},{"class":132,"line":2038},[5804],{"type":26,"tag":130,"props":5805,"children":5806},{"style":137},[5807],{"type":35,"value":380},{"type":26,"tag":1062,"props":5809,"children":5811},{"id":5810},"limitations-of-raw-threads",[5812],{"type":35,"value":5813},"Limitations of Raw Threads",{"type":26,"tag":896,"props":5815,"children":5816},{},[5817,5827,5837],{"type":26,"tag":54,"props":5818,"children":5819},{},[5820,5825],{"type":26,"tag":994,"props":5821,"children":5822},{},[5823],{"type":35,"value":5824},"Performance Overhead",{"type":35,"value":5826},": Creating and destroying threads is expensive.",{"type":26,"tag":54,"props":5828,"children":5829},{},[5830,5835],{"type":26,"tag":994,"props":5831,"children":5832},{},[5833],{"type":35,"value":5834},"No Pooling",{"type":35,"value":5836},": Each thread is a one-off. No built-in reuse.",{"type":26,"tag":54,"props":5838,"children":5839},{},[5840,5845],{"type":26,"tag":994,"props":5841,"children":5842},{},[5843],{"type":35,"value":5844},"Scalability Issues",{"type":35,"value":5846},": System resources limit the number of threads you can create.",{"type":26,"tag":31,"props":5848,"children":5849},{},[5850],{"type":35,"value":5851},"Using raw threads for large-scale concurrent applications quickly becomes impractical.",{"type":26,"tag":38,"props":5853,"children":5855},{"id":5854},"modern-concurrency-executorservice-and-thread-pooling",[5856],{"type":35,"value":5857},"Modern Concurrency: ExecutorService and Thread Pooling",{"type":26,"tag":31,"props":5859,"children":5860},{},[5861,5863,5868,5870,5876],{"type":35,"value":5862},"To solve the limitations of raw threads, Java introduced the ",{"type":26,"tag":15,"props":5864,"children":5866},{"className":5865},[],[5867],{"type":35,"value":5534},{"type":35,"value":5869}," as part of ",{"type":26,"tag":15,"props":5871,"children":5873},{"className":5872},[],[5874],{"type":35,"value":5875},"java.util.concurrent",{"type":35,"value":5877},". It provides a high-level API to manage and reuse threads through pooling.",{"type":26,"tag":1062,"props":5879,"children":5881},{"id":5880},"how-thread-pooling-works",[5882],{"type":35,"value":5883},"How Thread Pooling Works",{"type":26,"tag":31,"props":5885,"children":5886},{},[5887],{"type":35,"value":5888},"Thread pooling allows you to reuse a fixed number of threads to execute multiple tasks. Instead of creating a new thread for each task, the executor assigns tasks to available worker threads in the pool.",{"type":26,"tag":121,"props":5890,"children":5892},{"className":123,"code":5891,"language":17,"meta":8,"style":8},"import java.util.concurrent.ExecutorService;\nimport java.util.concurrent.Executors;\n\npublic class ExecutorExample {\n    public static void main(String[] args) {\n        ExecutorService executor = Executors.newFixedThreadPool(3);\n        for (int i = 0; i \u003C 5; i++) {\n            executor.submit(() -> System.out.println(\"Task executed by: \" + Thread.currentThread().getName()));\n        }\n        executor.shutdown();\n    }\n}\n",[5893],{"type":26,"tag":15,"props":5894,"children":5895},{"__ignoreMap":8},[5896,5908,5920,5927,5947,5986,6021,6080,6142,6150,6167,6174],{"type":26,"tag":130,"props":5897,"children":5898},{"class":132,"line":133},[5899,5903],{"type":26,"tag":130,"props":5900,"children":5901},{"style":143},[5902],{"type":35,"value":287},{"type":26,"tag":130,"props":5904,"children":5905},{"style":137},[5906],{"type":35,"value":5907}," java.util.concurrent.ExecutorService;\n",{"type":26,"tag":130,"props":5909,"children":5910},{"class":132,"line":176},[5911,5915],{"type":26,"tag":130,"props":5912,"children":5913},{"style":143},[5914],{"type":35,"value":287},{"type":26,"tag":130,"props":5916,"children":5917},{"style":137},[5918],{"type":35,"value":5919}," java.util.concurrent.Executors;\n",{"type":26,"tag":130,"props":5921,"children":5922},{"class":132,"line":205},[5923],{"type":26,"tag":130,"props":5924,"children":5925},{"emptyLinePlaceholder":298},[5926],{"type":35,"value":301},{"type":26,"tag":130,"props":5928,"children":5929},{"class":132,"line":231},[5930,5934,5938,5943],{"type":26,"tag":130,"props":5931,"children":5932},{"style":143},[5933],{"type":35,"value":3195},{"type":26,"tag":130,"props":5935,"children":5936},{"style":143},[5937],{"type":35,"value":3210},{"type":26,"tag":130,"props":5939,"children":5940},{"style":154},[5941],{"type":35,"value":5942}," ExecutorExample",{"type":26,"tag":130,"props":5944,"children":5945},{"style":137},[5946],{"type":35,"value":3285},{"type":26,"tag":130,"props":5948,"children":5949},{"class":132,"line":364},[5950,5954,5958,5962,5966,5970,5974,5978,5982],{"type":26,"tag":130,"props":5951,"children":5952},{"style":143},[5953],{"type":35,"value":3764},{"type":26,"tag":130,"props":5955,"children":5956},{"style":143},[5957],{"type":35,"value":3769},{"type":26,"tag":130,"props":5959,"children":5960},{"style":143},[5961],{"type":35,"value":3774},{"type":26,"tag":130,"props":5963,"children":5964},{"style":154},[5965],{"type":35,"value":3779},{"type":26,"tag":130,"props":5967,"children":5968},{"style":137},[5969],{"type":35,"value":162},{"type":26,"tag":130,"props":5971,"children":5972},{"style":143},[5973],{"type":35,"value":1426},{"type":26,"tag":130,"props":5975,"children":5976},{"style":137},[5977],{"type":35,"value":3792},{"type":26,"tag":130,"props":5979,"children":5980},{"style":3795},[5981],{"type":35,"value":3798},{"type":26,"tag":130,"props":5983,"children":5984},{"style":137},[5985],{"type":35,"value":3803},{"type":26,"tag":130,"props":5987,"children":5988},{"class":132,"line":374},[5989,5994,5998,6003,6008,6012,6017],{"type":26,"tag":130,"props":5990,"children":5991},{"style":137},[5992],{"type":35,"value":5993},"        ExecutorService executor ",{"type":26,"tag":130,"props":5995,"children":5996},{"style":143},[5997],{"type":35,"value":146},{"type":26,"tag":130,"props":5999,"children":6000},{"style":137},[6001],{"type":35,"value":6002}," Executors.",{"type":26,"tag":130,"props":6004,"children":6005},{"style":154},[6006],{"type":35,"value":6007},"newFixedThreadPool",{"type":26,"tag":130,"props":6009,"children":6010},{"style":137},[6011],{"type":35,"value":162},{"type":26,"tag":130,"props":6013,"children":6014},{"style":194},[6015],{"type":35,"value":6016},"3",{"type":26,"tag":130,"props":6018,"children":6019},{"style":137},[6020],{"type":35,"value":173},{"type":26,"tag":130,"props":6022,"children":6023},{"class":132,"line":1353},[6024,6029,6033,6038,6043,6047,6052,6057,6061,6066,6071,6076],{"type":26,"tag":130,"props":6025,"children":6026},{"style":143},[6027],{"type":35,"value":6028},"        for",{"type":26,"tag":130,"props":6030,"children":6031},{"style":137},[6032],{"type":35,"value":4460},{"type":26,"tag":130,"props":6034,"children":6035},{"style":143},[6036],{"type":35,"value":6037},"int",{"type":26,"tag":130,"props":6039,"children":6040},{"style":137},[6041],{"type":35,"value":6042}," i ",{"type":26,"tag":130,"props":6044,"children":6045},{"style":143},[6046],{"type":35,"value":146},{"type":26,"tag":130,"props":6048,"children":6049},{"style":194},[6050],{"type":35,"value":6051}," 0",{"type":26,"tag":130,"props":6053,"children":6054},{"style":137},[6055],{"type":35,"value":6056},"; i ",{"type":26,"tag":130,"props":6058,"children":6059},{"style":143},[6060],{"type":35,"value":719},{"type":26,"tag":130,"props":6062,"children":6063},{"style":194},[6064],{"type":35,"value":6065}," 5",{"type":26,"tag":130,"props":6067,"children":6068},{"style":137},[6069],{"type":35,"value":6070},"; i",{"type":26,"tag":130,"props":6072,"children":6073},{"style":143},[6074],{"type":35,"value":6075},"++",{"type":26,"tag":130,"props":6077,"children":6078},{"style":137},[6079],{"type":35,"value":3803},{"type":26,"tag":130,"props":6081,"children":6082},{"class":132,"line":1361},[6083,6088,6093,6097,6101,6105,6109,6113,6118,6122,6126,6130,6134,6138],{"type":26,"tag":130,"props":6084,"children":6085},{"style":137},[6086],{"type":35,"value":6087},"            executor.",{"type":26,"tag":130,"props":6089,"children":6090},{"style":154},[6091],{"type":35,"value":6092},"submit",{"type":26,"tag":130,"props":6094,"children":6095},{"style":137},[6096],{"type":35,"value":3839},{"type":26,"tag":130,"props":6098,"children":6099},{"style":143},[6100],{"type":35,"value":1454},{"type":26,"tag":130,"props":6102,"children":6103},{"style":137},[6104],{"type":35,"value":1549},{"type":26,"tag":130,"props":6106,"children":6107},{"style":154},[6108],{"type":35,"value":1554},{"type":26,"tag":130,"props":6110,"children":6111},{"style":137},[6112],{"type":35,"value":162},{"type":26,"tag":130,"props":6114,"children":6115},{"style":165},[6116],{"type":35,"value":6117},"\"Task executed by: \"",{"type":26,"tag":130,"props":6119,"children":6120},{"style":143},[6121],{"type":35,"value":1568},{"type":26,"tag":130,"props":6123,"children":6124},{"style":137},[6125],{"type":35,"value":5653},{"type":26,"tag":130,"props":6127,"children":6128},{"style":154},[6129],{"type":35,"value":5658},{"type":26,"tag":130,"props":6131,"children":6132},{"style":137},[6133],{"type":35,"value":5663},{"type":26,"tag":130,"props":6135,"children":6136},{"style":154},[6137],{"type":35,"value":5668},{"type":26,"tag":130,"props":6139,"children":6140},{"style":137},[6141],{"type":35,"value":1678},{"type":26,"tag":130,"props":6143,"children":6144},{"class":132,"line":1994},[6145],{"type":26,"tag":130,"props":6146,"children":6147},{"style":137},[6148],{"type":35,"value":6149},"        }\n",{"type":26,"tag":130,"props":6151,"children":6152},{"class":132,"line":2007},[6153,6158,6163],{"type":26,"tag":130,"props":6154,"children":6155},{"style":137},[6156],{"type":35,"value":6157},"        executor.",{"type":26,"tag":130,"props":6159,"children":6160},{"style":154},[6161],{"type":35,"value":6162},"shutdown",{"type":26,"tag":130,"props":6164,"children":6165},{"style":137},[6166],{"type":35,"value":256},{"type":26,"tag":130,"props":6168,"children":6169},{"class":132,"line":2020},[6170],{"type":26,"tag":130,"props":6171,"children":6172},{"style":137},[6173],{"type":35,"value":3962},{"type":26,"tag":130,"props":6175,"children":6176},{"class":132,"line":2038},[6177],{"type":26,"tag":130,"props":6178,"children":6179},{"style":137},[6180],{"type":35,"value":380},{"type":26,"tag":1062,"props":6182,"children":6184},{"id":6183},"common-executor-types",[6185],{"type":35,"value":6186},"Common Executor Types:",{"type":26,"tag":896,"props":6188,"children":6189},{},[6190,6201,6212,6223],{"type":26,"tag":54,"props":6191,"children":6192},{},[6193,6199],{"type":26,"tag":15,"props":6194,"children":6196},{"className":6195},[],[6197],{"type":35,"value":6198},"newFixedThreadPool(n)",{"type":35,"value":6200},": Fixed number of threads.",{"type":26,"tag":54,"props":6202,"children":6203},{},[6204,6210],{"type":26,"tag":15,"props":6205,"children":6207},{"className":6206},[],[6208],{"type":35,"value":6209},"newCachedThreadPool()",{"type":35,"value":6211},": Dynamically creates threads as needed.",{"type":26,"tag":54,"props":6213,"children":6214},{},[6215,6221],{"type":26,"tag":15,"props":6216,"children":6218},{"className":6217},[],[6219],{"type":35,"value":6220},"newSingleThreadExecutor()",{"type":35,"value":6222},": One thread for all tasks.",{"type":26,"tag":54,"props":6224,"children":6225},{},[6226,6232],{"type":26,"tag":15,"props":6227,"children":6229},{"className":6228},[],[6230],{"type":35,"value":6231},"newScheduledThreadPool(n)",{"type":35,"value":6233},": Supports delayed and periodic tasks.",{"type":26,"tag":1062,"props":6235,"children":6237},{"id":6236},"advantages",[6238],{"type":35,"value":6239},"Advantages:",{"type":26,"tag":896,"props":6241,"children":6242},{},[6243,6248,6253],{"type":26,"tag":54,"props":6244,"children":6245},{},[6246],{"type":35,"value":6247},"Efficient resource use through reuse.",{"type":26,"tag":54,"props":6249,"children":6250},{},[6251],{"type":35,"value":6252},"Better scalability and responsiveness.",{"type":26,"tag":54,"props":6254,"children":6255},{},[6256],{"type":35,"value":6257},"Built-in management of task queues and error handling.",{"type":26,"tag":38,"props":6259,"children":6261},{"id":6260},"the-future-virtual-threads-and-project-loom",[6262],{"type":35,"value":6263},"The Future: Virtual Threads and Project Loom",{"type":26,"tag":31,"props":6265,"children":6266},{},[6267],{"type":35,"value":6268},"Java 21 introduces Virtual Threads, a lightweight and scalable alternative to platform threads. A virtual thread is managed by the Java runtime rather than the operating system, allowing millions of threads to coexist.",{"type":26,"tag":1062,"props":6270,"children":6272},{"id":6271},"key-features",[6273],{"type":35,"value":6274},"Key Features:",{"type":26,"tag":896,"props":6276,"children":6277},{},[6278,6288,6298],{"type":26,"tag":54,"props":6279,"children":6280},{},[6281,6286],{"type":26,"tag":994,"props":6282,"children":6283},{},[6284],{"type":35,"value":6285},"Minimal Memory Footprint",{"type":35,"value":6287},": Much lighter than traditional threads.",{"type":26,"tag":54,"props":6289,"children":6290},{},[6291,6296],{"type":26,"tag":994,"props":6292,"children":6293},{},[6294],{"type":35,"value":6295},"Unblocked I/O",{"type":35,"value":6297},": I/O operations don’t block the underlying platform thread.",{"type":26,"tag":54,"props":6299,"children":6300},{},[6301,6306],{"type":26,"tag":994,"props":6302,"children":6303},{},[6304],{"type":35,"value":6305},"Massive Scalability",{"type":35,"value":6307},": Suitable for applications requiring thousands or millions of concurrent tasks (e.g., web servers).",{"type":26,"tag":31,"props":6309,"children":6310},{},[6311],{"type":35,"value":6312},"Example:",{"type":26,"tag":121,"props":6314,"children":6316},{"className":123,"code":6315,"language":17,"meta":8,"style":8},"public class VirtualThreadExample {\n    public static void main(String[] args) {\n        try (var executor = Executors.newVirtualThreadPerTaskExecutor()) {\n            for (int i = 0; i \u003C 10; i++) {\n                executor.submit(() -> {\n                    System.out.println(\"Running in: \" + Thread.currentThread().getName());\n                });\n            }\n        }\n    }\n}\n",[6317],{"type":26,"tag":15,"props":6318,"children":6319},{"__ignoreMap":8},[6320,6340,6379,6418,6471,6495,6540,6548,6556,6563,6570],{"type":26,"tag":130,"props":6321,"children":6322},{"class":132,"line":133},[6323,6327,6331,6336],{"type":26,"tag":130,"props":6324,"children":6325},{"style":143},[6326],{"type":35,"value":3195},{"type":26,"tag":130,"props":6328,"children":6329},{"style":143},[6330],{"type":35,"value":3210},{"type":26,"tag":130,"props":6332,"children":6333},{"style":154},[6334],{"type":35,"value":6335}," VirtualThreadExample",{"type":26,"tag":130,"props":6337,"children":6338},{"style":137},[6339],{"type":35,"value":3285},{"type":26,"tag":130,"props":6341,"children":6342},{"class":132,"line":176},[6343,6347,6351,6355,6359,6363,6367,6371,6375],{"type":26,"tag":130,"props":6344,"children":6345},{"style":143},[6346],{"type":35,"value":3764},{"type":26,"tag":130,"props":6348,"children":6349},{"style":143},[6350],{"type":35,"value":3769},{"type":26,"tag":130,"props":6352,"children":6353},{"style":143},[6354],{"type":35,"value":3774},{"type":26,"tag":130,"props":6356,"children":6357},{"style":154},[6358],{"type":35,"value":3779},{"type":26,"tag":130,"props":6360,"children":6361},{"style":137},[6362],{"type":35,"value":162},{"type":26,"tag":130,"props":6364,"children":6365},{"style":143},[6366],{"type":35,"value":1426},{"type":26,"tag":130,"props":6368,"children":6369},{"style":137},[6370],{"type":35,"value":3792},{"type":26,"tag":130,"props":6372,"children":6373},{"style":3795},[6374],{"type":35,"value":3798},{"type":26,"tag":130,"props":6376,"children":6377},{"style":137},[6378],{"type":35,"value":3803},{"type":26,"tag":130,"props":6380,"children":6381},{"class":132,"line":205},[6382,6386,6390,6395,6400,6404,6408,6413],{"type":26,"tag":130,"props":6383,"children":6384},{"style":143},[6385],{"type":35,"value":4012},{"type":26,"tag":130,"props":6387,"children":6388},{"style":137},[6389],{"type":35,"value":4460},{"type":26,"tag":130,"props":6391,"children":6392},{"style":143},[6393],{"type":35,"value":6394},"var",{"type":26,"tag":130,"props":6396,"children":6397},{"style":137},[6398],{"type":35,"value":6399}," executor ",{"type":26,"tag":130,"props":6401,"children":6402},{"style":143},[6403],{"type":35,"value":146},{"type":26,"tag":130,"props":6405,"children":6406},{"style":137},[6407],{"type":35,"value":6002},{"type":26,"tag":130,"props":6409,"children":6410},{"style":154},[6411],{"type":35,"value":6412},"newVirtualThreadPerTaskExecutor",{"type":26,"tag":130,"props":6414,"children":6415},{"style":137},[6416],{"type":35,"value":6417},"()) {\n",{"type":26,"tag":130,"props":6419,"children":6420},{"class":132,"line":231},[6421,6426,6430,6434,6438,6442,6446,6450,6454,6459,6463,6467],{"type":26,"tag":130,"props":6422,"children":6423},{"style":143},[6424],{"type":35,"value":6425},"            for",{"type":26,"tag":130,"props":6427,"children":6428},{"style":137},[6429],{"type":35,"value":4460},{"type":26,"tag":130,"props":6431,"children":6432},{"style":143},[6433],{"type":35,"value":6037},{"type":26,"tag":130,"props":6435,"children":6436},{"style":137},[6437],{"type":35,"value":6042},{"type":26,"tag":130,"props":6439,"children":6440},{"style":143},[6441],{"type":35,"value":146},{"type":26,"tag":130,"props":6443,"children":6444},{"style":194},[6445],{"type":35,"value":6051},{"type":26,"tag":130,"props":6447,"children":6448},{"style":137},[6449],{"type":35,"value":6056},{"type":26,"tag":130,"props":6451,"children":6452},{"style":143},[6453],{"type":35,"value":719},{"type":26,"tag":130,"props":6455,"children":6456},{"style":194},[6457],{"type":35,"value":6458}," 10",{"type":26,"tag":130,"props":6460,"children":6461},{"style":137},[6462],{"type":35,"value":6070},{"type":26,"tag":130,"props":6464,"children":6465},{"style":143},[6466],{"type":35,"value":6075},{"type":26,"tag":130,"props":6468,"children":6469},{"style":137},[6470],{"type":35,"value":3803},{"type":26,"tag":130,"props":6472,"children":6473},{"class":132,"line":364},[6474,6479,6483,6487,6491],{"type":26,"tag":130,"props":6475,"children":6476},{"style":137},[6477],{"type":35,"value":6478},"                executor.",{"type":26,"tag":130,"props":6480,"children":6481},{"style":154},[6482],{"type":35,"value":6092},{"type":26,"tag":130,"props":6484,"children":6485},{"style":137},[6486],{"type":35,"value":3839},{"type":26,"tag":130,"props":6488,"children":6489},{"style":143},[6490],{"type":35,"value":1454},{"type":26,"tag":130,"props":6492,"children":6493},{"style":137},[6494],{"type":35,"value":3285},{"type":26,"tag":130,"props":6496,"children":6497},{"class":132,"line":374},[6498,6503,6507,6511,6516,6520,6524,6528,6532,6536],{"type":26,"tag":130,"props":6499,"children":6500},{"style":137},[6501],{"type":35,"value":6502},"                    System.out.",{"type":26,"tag":130,"props":6504,"children":6505},{"style":154},[6506],{"type":35,"value":1554},{"type":26,"tag":130,"props":6508,"children":6509},{"style":137},[6510],{"type":35,"value":162},{"type":26,"tag":130,"props":6512,"children":6513},{"style":165},[6514],{"type":35,"value":6515},"\"Running in: \"",{"type":26,"tag":130,"props":6517,"children":6518},{"style":143},[6519],{"type":35,"value":1568},{"type":26,"tag":130,"props":6521,"children":6522},{"style":137},[6523],{"type":35,"value":5653},{"type":26,"tag":130,"props":6525,"children":6526},{"style":154},[6527],{"type":35,"value":5658},{"type":26,"tag":130,"props":6529,"children":6530},{"style":137},[6531],{"type":35,"value":5663},{"type":26,"tag":130,"props":6533,"children":6534},{"style":154},[6535],{"type":35,"value":5668},{"type":26,"tag":130,"props":6537,"children":6538},{"style":137},[6539],{"type":35,"value":338},{"type":26,"tag":130,"props":6541,"children":6542},{"class":132,"line":1353},[6543],{"type":26,"tag":130,"props":6544,"children":6545},{"style":137},[6546],{"type":35,"value":6547},"                });\n",{"type":26,"tag":130,"props":6549,"children":6550},{"class":132,"line":1361},[6551],{"type":26,"tag":130,"props":6552,"children":6553},{"style":137},[6554],{"type":35,"value":6555},"            }\n",{"type":26,"tag":130,"props":6557,"children":6558},{"class":132,"line":1994},[6559],{"type":26,"tag":130,"props":6560,"children":6561},{"style":137},[6562],{"type":35,"value":6149},{"type":26,"tag":130,"props":6564,"children":6565},{"class":132,"line":2007},[6566],{"type":26,"tag":130,"props":6567,"children":6568},{"style":137},[6569],{"type":35,"value":3962},{"type":26,"tag":130,"props":6571,"children":6572},{"class":132,"line":2020},[6573],{"type":26,"tag":130,"props":6574,"children":6575},{"style":137},[6576],{"type":35,"value":380},{"type":26,"tag":1062,"props":6578,"children":6580},{"id":6579},"when-to-use-virtual-threads",[6581],{"type":35,"value":6582},"When to Use Virtual Threads:",{"type":26,"tag":896,"props":6584,"children":6585},{},[6586,6591,6596],{"type":26,"tag":54,"props":6587,"children":6588},{},[6589],{"type":35,"value":6590},"I/O-bound applications (e.g., database access, HTTP clients).",{"type":26,"tag":54,"props":6592,"children":6593},{},[6594],{"type":35,"value":6595},"High-concurrency workloads (e.g., messaging systems).",{"type":26,"tag":54,"props":6597,"children":6598},{},[6599],{"type":35,"value":6600},"When simplifying thread management is a priority.",{"type":26,"tag":38,"props":6602,"children":6603},{"id":879},[6604],{"type":35,"value":882},{"type":26,"tag":31,"props":6606,"children":6607},{},[6608],{"type":35,"value":6609},"Java offers a flexible and powerful concurrency model. Classic Threads provide a foundational understanding, ExecutorService enables efficient thread reuse and task management, and Virtual Threads open the door to a new era of scalable concurrency with minimal overhead.",{"type":26,"tag":31,"props":6611,"children":6612},{},[6613],{"type":35,"value":6614},"Each model has its place depending on the problem at hand. Mastering them gives you the toolkit needed to build high-performance, concurrent applications.",{"type":26,"tag":38,"props":6616,"children":6617},{"id":891},[6618],{"type":35,"value":894},{"type":26,"tag":896,"props":6620,"children":6621},{},[6622,6632,6642,6651],{"type":26,"tag":54,"props":6623,"children":6624},{},[6625],{"type":26,"tag":903,"props":6626,"children":6629},{"href":6627,"rel":6628},"https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/package-summary.html",[907],[6630],{"type":35,"value":6631},"Java Concurrency API",{"type":26,"tag":54,"props":6633,"children":6634},{},[6635],{"type":26,"tag":903,"props":6636,"children":6639},{"href":6637,"rel":6638},"https://openjdk.org/projects/loom/",[907],[6640],{"type":35,"value":6641},"Project Loom (Virtual Threads)",{"type":26,"tag":54,"props":6643,"children":6644},{},[6645],{"type":26,"tag":903,"props":6646,"children":6649},{"href":6647,"rel":6648},"https://docs.oracle.com/javase/tutorial/essential/concurrency/forkjoin.html",[907],[6650],{"type":35,"value":5511},{"type":26,"tag":54,"props":6652,"children":6653},{},[6654],{"type":26,"tag":903,"props":6655,"children":6658},{"href":6656,"rel":6657},"https://www.oreilly.com/library/view/effective-java-3rd/9780134686097/",[907],[6659],{"type":35,"value":6660},"Effective Java - Joshua Bloch",{"type":26,"tag":31,"props":6662,"children":6663},{},[6664],{"type":35,"value":6665},"Deep understanding of Java's concurrency tools can significantly improve your system’s performance, scalability, and maintainability.",{"type":26,"tag":932,"props":6667,"children":6668},{},[6669],{"type":35,"value":936},{"title":8,"searchDepth":176,"depth":176,"links":6671},[6672,6673,6676,6681,6685,6686],{"id":5462,"depth":176,"text":5465},{"id":5539,"depth":176,"text":5542,"children":6674},[6675],{"id":5810,"depth":205,"text":5813},{"id":5854,"depth":176,"text":5857,"children":6677},[6678,6679,6680],{"id":5880,"depth":205,"text":5883},{"id":6183,"depth":205,"text":6186},{"id":6236,"depth":205,"text":6239},{"id":6260,"depth":176,"text":6263,"children":6682},[6683,6684],{"id":6271,"depth":205,"text":6274},{"id":6579,"depth":205,"text":6582},{"id":879,"depth":176,"text":882},{"id":891,"depth":176,"text":894},"content:posts:mastering-concurrency.md","posts/mastering-concurrency.md","posts/mastering-concurrency",{"_path":6691,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":6692,"description":6693,"date":6694,"layout":12,"subtitle":6695,"image":6696,"optimized_image":6696,"category":15,"tags":6697,"author":21,"paginate":7,"body":6700,"_type":949,"_id":7707,"_source":951,"_file":7708,"_stem":7709,"_extension":954},"/posts/tdd-testing","Test-Driven Development (TDD) in Java with JUnit and Mockito","Understanding Test-Driven Development (TDD) in Java using JUnit and Mockito with practical examples.","2024-01-15T11:00:00.000Z","Writing Better Code with Automated Testing","/assets/img/uploads/tdd-java.png",[15,17,6698,6699],"testing","tdd",{"type":23,"children":6701,"toc":7700},[6702,6710,6716,6721,6739,6744,6750,6758,6763,6768,6949,6957,6962,6967,7234,7240,7245,7456,7461,7635,7640,7644,7649,7653,7658,7691,7696],{"type":26,"tag":27,"props":6703,"children":6704},{},[6705],{"type":26,"tag":31,"props":6706,"children":6707},{},[6708],{"type":35,"value":6709},"In modern software development, ensuring code quality and reliability is crucial. Many job interviews for Java developers assess knowledge of automated testing frameworks like JUnit and Mockito. Test-Driven Development (TDD) is a methodology that not only enhances code quality but is also a highly sought-after skill in the industry.",{"type":26,"tag":38,"props":6711,"children":6713},{"id":6712},"what-is-tdd",[6714],{"type":35,"value":6715},"What is TDD?",{"type":26,"tag":31,"props":6717,"children":6718},{},[6719],{"type":35,"value":6720},"Test-Driven Development (TDD) is a software development methodology where tests are written before implementing functionality. It follows a repetitive cycle known as \"Red-Green-Refactor\":",{"type":26,"tag":896,"props":6722,"children":6723},{},[6724,6729,6734],{"type":26,"tag":54,"props":6725,"children":6726},{},[6727],{"type":35,"value":6728},"Red: Write a test that fails (since the functionality is not yet implemented).",{"type":26,"tag":54,"props":6730,"children":6731},{},[6732],{"type":35,"value":6733},"Green: Write the minimal code required to pass the test.",{"type":26,"tag":54,"props":6735,"children":6736},{},[6737],{"type":35,"value":6738},"Refactor: Improve the code while ensuring the test still passes.",{"type":26,"tag":31,"props":6740,"children":6741},{},[6742],{"type":35,"value":6743},"This approach ensures that each piece of code is tested, making maintenance easier and reducing the likelihood of errors.",{"type":26,"tag":38,"props":6745,"children":6747},{"id":6746},"introduction-to-junit-and-mockito",[6748],{"type":35,"value":6749},"Introduction to JUnit and Mockito",{"type":26,"tag":31,"props":6751,"children":6752},{},[6753],{"type":26,"tag":994,"props":6754,"children":6755},{},[6756],{"type":35,"value":6757},"JUnit",{"type":26,"tag":31,"props":6759,"children":6760},{},[6761],{"type":35,"value":6762},"JUnit is the most widely used unit testing framework in Java. It allows developers to write and execute automated tests efficiently.",{"type":26,"tag":31,"props":6764,"children":6765},{},[6766],{"type":35,"value":6767},"Example of a simple test with JUnit 5:",{"type":26,"tag":121,"props":6769,"children":6771},{"className":123,"code":6770,"language":17,"meta":8,"style":8},"import org.junit.jupiter.api.Test;\nimport static org.junit.jupiter.api.Assertions.*;\n\nclass CalculatorTest {\n    @Test\n    void testSum() {\n        Calculator calc = new Calculator();\n        assertEquals(5, calc.add(2, 3));\n    }\n}\n",[6772],{"type":26,"tag":15,"props":6773,"children":6774},{"__ignoreMap":8},[6775,6787,6811,6818,6834,6847,6864,6889,6935,6942],{"type":26,"tag":130,"props":6776,"children":6777},{"class":132,"line":133},[6778,6782],{"type":26,"tag":130,"props":6779,"children":6780},{"style":143},[6781],{"type":35,"value":287},{"type":26,"tag":130,"props":6783,"children":6784},{"style":137},[6785],{"type":35,"value":6786}," org.junit.jupiter.api.Test;\n",{"type":26,"tag":130,"props":6788,"children":6789},{"class":132,"line":176},[6790,6794,6798,6803,6807],{"type":26,"tag":130,"props":6791,"children":6792},{"style":143},[6793],{"type":35,"value":287},{"type":26,"tag":130,"props":6795,"children":6796},{"style":143},[6797],{"type":35,"value":3769},{"type":26,"tag":130,"props":6799,"children":6800},{"style":137},[6801],{"type":35,"value":6802}," org.junit.jupiter.api.Assertions.",{"type":26,"tag":130,"props":6804,"children":6805},{"style":194},[6806],{"type":35,"value":3460},{"type":26,"tag":130,"props":6808,"children":6809},{"style":137},[6810],{"type":35,"value":2889},{"type":26,"tag":130,"props":6812,"children":6813},{"class":132,"line":205},[6814],{"type":26,"tag":130,"props":6815,"children":6816},{"emptyLinePlaceholder":298},[6817],{"type":35,"value":301},{"type":26,"tag":130,"props":6819,"children":6820},{"class":132,"line":231},[6821,6825,6830],{"type":26,"tag":130,"props":6822,"children":6823},{"style":143},[6824],{"type":35,"value":5585},{"type":26,"tag":130,"props":6826,"children":6827},{"style":154},[6828],{"type":35,"value":6829}," CalculatorTest",{"type":26,"tag":130,"props":6831,"children":6832},{"style":137},[6833],{"type":35,"value":3285},{"type":26,"tag":130,"props":6835,"children":6836},{"class":132,"line":364},[6837,6842],{"type":26,"tag":130,"props":6838,"children":6839},{"style":137},[6840],{"type":35,"value":6841},"    @",{"type":26,"tag":130,"props":6843,"children":6844},{"style":143},[6845],{"type":35,"value":6846},"Test\n",{"type":26,"tag":130,"props":6848,"children":6849},{"class":132,"line":374},[6850,6855,6860],{"type":26,"tag":130,"props":6851,"children":6852},{"style":143},[6853],{"type":35,"value":6854},"    void",{"type":26,"tag":130,"props":6856,"children":6857},{"style":154},[6858],{"type":35,"value":6859}," testSum",{"type":26,"tag":130,"props":6861,"children":6862},{"style":137},[6863],{"type":35,"value":5624},{"type":26,"tag":130,"props":6865,"children":6866},{"class":132,"line":1353},[6867,6872,6876,6880,6885],{"type":26,"tag":130,"props":6868,"children":6869},{"style":137},[6870],{"type":35,"value":6871},"        Calculator calc ",{"type":26,"tag":130,"props":6873,"children":6874},{"style":143},[6875],{"type":35,"value":146},{"type":26,"tag":130,"props":6877,"children":6878},{"style":143},[6879],{"type":35,"value":627},{"type":26,"tag":130,"props":6881,"children":6882},{"style":154},[6883],{"type":35,"value":6884}," Calculator",{"type":26,"tag":130,"props":6886,"children":6887},{"style":137},[6888],{"type":35,"value":256},{"type":26,"tag":130,"props":6890,"children":6891},{"class":132,"line":1361},[6892,6897,6901,6905,6910,6915,6919,6923,6927,6931],{"type":26,"tag":130,"props":6893,"children":6894},{"style":154},[6895],{"type":35,"value":6896},"        assertEquals",{"type":26,"tag":130,"props":6898,"children":6899},{"style":137},[6900],{"type":35,"value":162},{"type":26,"tag":130,"props":6902,"children":6903},{"style":194},[6904],{"type":35,"value":1330},{"type":26,"tag":130,"props":6906,"children":6907},{"style":137},[6908],{"type":35,"value":6909},", calc.",{"type":26,"tag":130,"props":6911,"children":6912},{"style":154},[6913],{"type":35,"value":6914},"add",{"type":26,"tag":130,"props":6916,"children":6917},{"style":137},[6918],{"type":35,"value":162},{"type":26,"tag":130,"props":6920,"children":6921},{"style":194},[6922],{"type":35,"value":223},{"type":26,"tag":130,"props":6924,"children":6925},{"style":137},[6926],{"type":35,"value":3233},{"type":26,"tag":130,"props":6928,"children":6929},{"style":194},[6930],{"type":35,"value":6016},{"type":26,"tag":130,"props":6932,"children":6933},{"style":137},[6934],{"type":35,"value":660},{"type":26,"tag":130,"props":6936,"children":6937},{"class":132,"line":1994},[6938],{"type":26,"tag":130,"props":6939,"children":6940},{"style":137},[6941],{"type":35,"value":3962},{"type":26,"tag":130,"props":6943,"children":6944},{"class":132,"line":2007},[6945],{"type":26,"tag":130,"props":6946,"children":6947},{"style":137},[6948],{"type":35,"value":380},{"type":26,"tag":31,"props":6950,"children":6951},{},[6952],{"type":26,"tag":994,"props":6953,"children":6954},{},[6955],{"type":35,"value":6956},"Mockito",{"type":26,"tag":31,"props":6958,"children":6959},{},[6960],{"type":35,"value":6961},"Mockito is a framework that enables the creation of mock objects for unit testing. It is useful when testing components that depend on external services, such as databases or APIs.",{"type":26,"tag":31,"props":6963,"children":6964},{},[6965],{"type":35,"value":6966},"Example using Mockito:",{"type":26,"tag":121,"props":6968,"children":6970},{"className":123,"code":6969,"language":17,"meta":8,"style":8},"import org.junit.jupiter.api.Test;\nimport org.mockito.Mockito;\nimport static org.mockito.Mockito.*;\nimport static org.junit.jupiter.api.Assertions.*;\n\nclass ServiceTest {\n    @Test\n    void testService() {\n        ExternalService serviceMock = mock(ExternalService.class);\n        when(serviceMock.getData()).thenReturn(\"Mocked data\");\n        \n        Client client = new Client(serviceMock);\n        assertEquals(\"Mocked data\", client.getInformation());\n    }\n}\n\n",[6971],{"type":26,"tag":15,"props":6972,"children":6973},{"__ignoreMap":8},[6974,6985,6997,7021,7044,7051,7067,7078,7094,7116,7157,7165,7191,7220,7227],{"type":26,"tag":130,"props":6975,"children":6976},{"class":132,"line":133},[6977,6981],{"type":26,"tag":130,"props":6978,"children":6979},{"style":143},[6980],{"type":35,"value":287},{"type":26,"tag":130,"props":6982,"children":6983},{"style":137},[6984],{"type":35,"value":6786},{"type":26,"tag":130,"props":6986,"children":6987},{"class":132,"line":176},[6988,6992],{"type":26,"tag":130,"props":6989,"children":6990},{"style":143},[6991],{"type":35,"value":287},{"type":26,"tag":130,"props":6993,"children":6994},{"style":137},[6995],{"type":35,"value":6996}," org.mockito.Mockito;\n",{"type":26,"tag":130,"props":6998,"children":6999},{"class":132,"line":205},[7000,7004,7008,7013,7017],{"type":26,"tag":130,"props":7001,"children":7002},{"style":143},[7003],{"type":35,"value":287},{"type":26,"tag":130,"props":7005,"children":7006},{"style":143},[7007],{"type":35,"value":3769},{"type":26,"tag":130,"props":7009,"children":7010},{"style":137},[7011],{"type":35,"value":7012}," org.mockito.Mockito.",{"type":26,"tag":130,"props":7014,"children":7015},{"style":194},[7016],{"type":35,"value":3460},{"type":26,"tag":130,"props":7018,"children":7019},{"style":137},[7020],{"type":35,"value":2889},{"type":26,"tag":130,"props":7022,"children":7023},{"class":132,"line":231},[7024,7028,7032,7036,7040],{"type":26,"tag":130,"props":7025,"children":7026},{"style":143},[7027],{"type":35,"value":287},{"type":26,"tag":130,"props":7029,"children":7030},{"style":143},[7031],{"type":35,"value":3769},{"type":26,"tag":130,"props":7033,"children":7034},{"style":137},[7035],{"type":35,"value":6802},{"type":26,"tag":130,"props":7037,"children":7038},{"style":194},[7039],{"type":35,"value":3460},{"type":26,"tag":130,"props":7041,"children":7042},{"style":137},[7043],{"type":35,"value":2889},{"type":26,"tag":130,"props":7045,"children":7046},{"class":132,"line":364},[7047],{"type":26,"tag":130,"props":7048,"children":7049},{"emptyLinePlaceholder":298},[7050],{"type":35,"value":301},{"type":26,"tag":130,"props":7052,"children":7053},{"class":132,"line":374},[7054,7058,7063],{"type":26,"tag":130,"props":7055,"children":7056},{"style":143},[7057],{"type":35,"value":5585},{"type":26,"tag":130,"props":7059,"children":7060},{"style":154},[7061],{"type":35,"value":7062}," ServiceTest",{"type":26,"tag":130,"props":7064,"children":7065},{"style":137},[7066],{"type":35,"value":3285},{"type":26,"tag":130,"props":7068,"children":7069},{"class":132,"line":1353},[7070,7074],{"type":26,"tag":130,"props":7071,"children":7072},{"style":137},[7073],{"type":35,"value":6841},{"type":26,"tag":130,"props":7075,"children":7076},{"style":143},[7077],{"type":35,"value":6846},{"type":26,"tag":130,"props":7079,"children":7080},{"class":132,"line":1361},[7081,7085,7090],{"type":26,"tag":130,"props":7082,"children":7083},{"style":143},[7084],{"type":35,"value":6854},{"type":26,"tag":130,"props":7086,"children":7087},{"style":154},[7088],{"type":35,"value":7089}," testService",{"type":26,"tag":130,"props":7091,"children":7092},{"style":137},[7093],{"type":35,"value":5624},{"type":26,"tag":130,"props":7095,"children":7096},{"class":132,"line":1994},[7097,7102,7106,7111],{"type":26,"tag":130,"props":7098,"children":7099},{"style":137},[7100],{"type":35,"value":7101},"        ExternalService serviceMock ",{"type":26,"tag":130,"props":7103,"children":7104},{"style":143},[7105],{"type":35,"value":146},{"type":26,"tag":130,"props":7107,"children":7108},{"style":154},[7109],{"type":35,"value":7110}," mock",{"type":26,"tag":130,"props":7112,"children":7113},{"style":137},[7114],{"type":35,"value":7115},"(ExternalService.class);\n",{"type":26,"tag":130,"props":7117,"children":7118},{"class":132,"line":2007},[7119,7124,7129,7134,7139,7144,7148,7153],{"type":26,"tag":130,"props":7120,"children":7121},{"style":154},[7122],{"type":35,"value":7123},"        when",{"type":26,"tag":130,"props":7125,"children":7126},{"style":137},[7127],{"type":35,"value":7128},"(serviceMock.",{"type":26,"tag":130,"props":7130,"children":7131},{"style":154},[7132],{"type":35,"value":7133},"getData",{"type":26,"tag":130,"props":7135,"children":7136},{"style":137},[7137],{"type":35,"value":7138},"()).",{"type":26,"tag":130,"props":7140,"children":7141},{"style":154},[7142],{"type":35,"value":7143},"thenReturn",{"type":26,"tag":130,"props":7145,"children":7146},{"style":137},[7147],{"type":35,"value":162},{"type":26,"tag":130,"props":7149,"children":7150},{"style":165},[7151],{"type":35,"value":7152},"\"Mocked data\"",{"type":26,"tag":130,"props":7154,"children":7155},{"style":137},[7156],{"type":35,"value":173},{"type":26,"tag":130,"props":7158,"children":7159},{"class":132,"line":2020},[7160],{"type":26,"tag":130,"props":7161,"children":7162},{"style":137},[7163],{"type":35,"value":7164},"        \n",{"type":26,"tag":130,"props":7166,"children":7167},{"class":132,"line":2038},[7168,7173,7177,7181,7186],{"type":26,"tag":130,"props":7169,"children":7170},{"style":137},[7171],{"type":35,"value":7172},"        Client client ",{"type":26,"tag":130,"props":7174,"children":7175},{"style":143},[7176],{"type":35,"value":146},{"type":26,"tag":130,"props":7178,"children":7179},{"style":143},[7180],{"type":35,"value":627},{"type":26,"tag":130,"props":7182,"children":7183},{"style":154},[7184],{"type":35,"value":7185}," Client",{"type":26,"tag":130,"props":7187,"children":7188},{"style":137},[7189],{"type":35,"value":7190},"(serviceMock);\n",{"type":26,"tag":130,"props":7192,"children":7193},{"class":132,"line":2046},[7194,7198,7202,7206,7211,7216],{"type":26,"tag":130,"props":7195,"children":7196},{"style":154},[7197],{"type":35,"value":6896},{"type":26,"tag":130,"props":7199,"children":7200},{"style":137},[7201],{"type":35,"value":162},{"type":26,"tag":130,"props":7203,"children":7204},{"style":165},[7205],{"type":35,"value":7152},{"type":26,"tag":130,"props":7207,"children":7208},{"style":137},[7209],{"type":35,"value":7210},", client.",{"type":26,"tag":130,"props":7212,"children":7213},{"style":154},[7214],{"type":35,"value":7215},"getInformation",{"type":26,"tag":130,"props":7217,"children":7218},{"style":137},[7219],{"type":35,"value":338},{"type":26,"tag":130,"props":7221,"children":7222},{"class":132,"line":2059},[7223],{"type":26,"tag":130,"props":7224,"children":7225},{"style":137},[7226],{"type":35,"value":3962},{"type":26,"tag":130,"props":7228,"children":7229},{"class":132,"line":2082},[7230],{"type":26,"tag":130,"props":7231,"children":7232},{"style":137},[7233],{"type":35,"value":380},{"type":26,"tag":38,"props":7235,"children":7237},{"id":7236},"tdd-in-action-a-practical-example",[7238],{"type":35,"value":7239},"TDD in Action: A Practical Example",{"type":26,"tag":31,"props":7241,"children":7242},{},[7243],{"type":35,"value":7244},"Let's say we need to develop a user management service. First, we write a failing test:",{"type":26,"tag":121,"props":7246,"children":7248},{"className":123,"code":7247,"language":17,"meta":8,"style":8},"@Test\nvoid testAddUser() {\n    UserRepository repoMock = mock(UserRepository.class);\n    UserService service = new UserService(repoMock);\n    \n    User user = new User(\"John\", \"john@example.com\");\n    when(repoMock.save(user)).thenReturn(true);\n    \n    assertTrue(service.registerUser(user));\n} \n",[7249],{"type":26,"tag":15,"props":7250,"children":7251},{"__ignoreMap":8},[7252,7264,7281,7302,7328,7336,7379,7419,7426,7449],{"type":26,"tag":130,"props":7253,"children":7254},{"class":132,"line":133},[7255,7260],{"type":26,"tag":130,"props":7256,"children":7257},{"style":137},[7258],{"type":35,"value":7259},"@",{"type":26,"tag":130,"props":7261,"children":7262},{"style":143},[7263],{"type":35,"value":6846},{"type":26,"tag":130,"props":7265,"children":7266},{"class":132,"line":176},[7267,7272,7277],{"type":26,"tag":130,"props":7268,"children":7269},{"style":143},[7270],{"type":35,"value":7271},"void",{"type":26,"tag":130,"props":7273,"children":7274},{"style":154},[7275],{"type":35,"value":7276}," testAddUser",{"type":26,"tag":130,"props":7278,"children":7279},{"style":137},[7280],{"type":35,"value":5624},{"type":26,"tag":130,"props":7282,"children":7283},{"class":132,"line":205},[7284,7289,7293,7297],{"type":26,"tag":130,"props":7285,"children":7286},{"style":137},[7287],{"type":35,"value":7288},"    UserRepository repoMock ",{"type":26,"tag":130,"props":7290,"children":7291},{"style":143},[7292],{"type":35,"value":146},{"type":26,"tag":130,"props":7294,"children":7295},{"style":154},[7296],{"type":35,"value":7110},{"type":26,"tag":130,"props":7298,"children":7299},{"style":137},[7300],{"type":35,"value":7301},"(UserRepository.class);\n",{"type":26,"tag":130,"props":7303,"children":7304},{"class":132,"line":231},[7305,7310,7314,7318,7323],{"type":26,"tag":130,"props":7306,"children":7307},{"style":137},[7308],{"type":35,"value":7309},"    UserService service ",{"type":26,"tag":130,"props":7311,"children":7312},{"style":143},[7313],{"type":35,"value":146},{"type":26,"tag":130,"props":7315,"children":7316},{"style":143},[7317],{"type":35,"value":627},{"type":26,"tag":130,"props":7319,"children":7320},{"style":154},[7321],{"type":35,"value":7322}," UserService",{"type":26,"tag":130,"props":7324,"children":7325},{"style":137},[7326],{"type":35,"value":7327},"(repoMock);\n",{"type":26,"tag":130,"props":7329,"children":7330},{"class":132,"line":364},[7331],{"type":26,"tag":130,"props":7332,"children":7333},{"style":137},[7334],{"type":35,"value":7335},"    \n",{"type":26,"tag":130,"props":7337,"children":7338},{"class":132,"line":374},[7339,7344,7348,7352,7357,7361,7366,7370,7375],{"type":26,"tag":130,"props":7340,"children":7341},{"style":137},[7342],{"type":35,"value":7343},"    User user ",{"type":26,"tag":130,"props":7345,"children":7346},{"style":143},[7347],{"type":35,"value":146},{"type":26,"tag":130,"props":7349,"children":7350},{"style":143},[7351],{"type":35,"value":627},{"type":26,"tag":130,"props":7353,"children":7354},{"style":154},[7355],{"type":35,"value":7356}," User",{"type":26,"tag":130,"props":7358,"children":7359},{"style":137},[7360],{"type":35,"value":162},{"type":26,"tag":130,"props":7362,"children":7363},{"style":165},[7364],{"type":35,"value":7365},"\"John\"",{"type":26,"tag":130,"props":7367,"children":7368},{"style":137},[7369],{"type":35,"value":3233},{"type":26,"tag":130,"props":7371,"children":7372},{"style":165},[7373],{"type":35,"value":7374},"\"john@example.com\"",{"type":26,"tag":130,"props":7376,"children":7377},{"style":137},[7378],{"type":35,"value":173},{"type":26,"tag":130,"props":7380,"children":7381},{"class":132,"line":1353},[7382,7387,7392,7397,7402,7406,7410,7415],{"type":26,"tag":130,"props":7383,"children":7384},{"style":154},[7385],{"type":35,"value":7386},"    when",{"type":26,"tag":130,"props":7388,"children":7389},{"style":137},[7390],{"type":35,"value":7391},"(repoMock.",{"type":26,"tag":130,"props":7393,"children":7394},{"style":154},[7395],{"type":35,"value":7396},"save",{"type":26,"tag":130,"props":7398,"children":7399},{"style":137},[7400],{"type":35,"value":7401},"(user)).",{"type":26,"tag":130,"props":7403,"children":7404},{"style":154},[7405],{"type":35,"value":7143},{"type":26,"tag":130,"props":7407,"children":7408},{"style":137},[7409],{"type":35,"value":162},{"type":26,"tag":130,"props":7411,"children":7412},{"style":194},[7413],{"type":35,"value":7414},"true",{"type":26,"tag":130,"props":7416,"children":7417},{"style":137},[7418],{"type":35,"value":173},{"type":26,"tag":130,"props":7420,"children":7421},{"class":132,"line":1361},[7422],{"type":26,"tag":130,"props":7423,"children":7424},{"style":137},[7425],{"type":35,"value":7335},{"type":26,"tag":130,"props":7427,"children":7428},{"class":132,"line":1994},[7429,7434,7439,7444],{"type":26,"tag":130,"props":7430,"children":7431},{"style":154},[7432],{"type":35,"value":7433},"    assertTrue",{"type":26,"tag":130,"props":7435,"children":7436},{"style":137},[7437],{"type":35,"value":7438},"(service.",{"type":26,"tag":130,"props":7440,"children":7441},{"style":154},[7442],{"type":35,"value":7443},"registerUser",{"type":26,"tag":130,"props":7445,"children":7446},{"style":137},[7447],{"type":35,"value":7448},"(user));\n",{"type":26,"tag":130,"props":7450,"children":7451},{"class":132,"line":2007},[7452],{"type":26,"tag":130,"props":7453,"children":7454},{"style":137},[7455],{"type":35,"value":380},{"type":26,"tag":31,"props":7457,"children":7458},{},[7459],{"type":35,"value":7460},"Next, we implement the minimal functionality required for the test to pass:",{"type":26,"tag":121,"props":7462,"children":7464},{"className":123,"code":7463,"language":17,"meta":8,"style":8},"class UserService {\nprivate final UserRepository repository;\n    \n    public UserService(UserRepository repository) {\n        this.repository = repository;\n    }\n    \n    public boolean registerUser(User user) {\n        return repository.save(user);\n    }\n}\n",[7465],{"type":26,"tag":15,"props":7466,"children":7467},{"__ignoreMap":8},[7468,7483,7500,7507,7532,7554,7561,7568,7599,7621,7628],{"type":26,"tag":130,"props":7469,"children":7470},{"class":132,"line":133},[7471,7475,7479],{"type":26,"tag":130,"props":7472,"children":7473},{"style":143},[7474],{"type":35,"value":5585},{"type":26,"tag":130,"props":7476,"children":7477},{"style":154},[7478],{"type":35,"value":7322},{"type":26,"tag":130,"props":7480,"children":7481},{"style":137},[7482],{"type":35,"value":3285},{"type":26,"tag":130,"props":7484,"children":7485},{"class":132,"line":176},[7486,7491,7495],{"type":26,"tag":130,"props":7487,"children":7488},{"style":143},[7489],{"type":35,"value":7490},"private",{"type":26,"tag":130,"props":7492,"children":7493},{"style":143},[7494],{"type":35,"value":3262},{"type":26,"tag":130,"props":7496,"children":7497},{"style":137},[7498],{"type":35,"value":7499}," UserRepository repository;\n",{"type":26,"tag":130,"props":7501,"children":7502},{"class":132,"line":205},[7503],{"type":26,"tag":130,"props":7504,"children":7505},{"style":137},[7506],{"type":35,"value":7335},{"type":26,"tag":130,"props":7508,"children":7509},{"class":132,"line":231},[7510,7514,7518,7523,7528],{"type":26,"tag":130,"props":7511,"children":7512},{"style":143},[7513],{"type":35,"value":3764},{"type":26,"tag":130,"props":7515,"children":7516},{"style":154},[7517],{"type":35,"value":7322},{"type":26,"tag":130,"props":7519,"children":7520},{"style":137},[7521],{"type":35,"value":7522},"(UserRepository ",{"type":26,"tag":130,"props":7524,"children":7525},{"style":3795},[7526],{"type":35,"value":7527},"repository",{"type":26,"tag":130,"props":7529,"children":7530},{"style":137},[7531],{"type":35,"value":3803},{"type":26,"tag":130,"props":7533,"children":7534},{"class":132,"line":364},[7535,7540,7545,7549],{"type":26,"tag":130,"props":7536,"children":7537},{"style":194},[7538],{"type":35,"value":7539},"        this",{"type":26,"tag":130,"props":7541,"children":7542},{"style":137},[7543],{"type":35,"value":7544},".repository ",{"type":26,"tag":130,"props":7546,"children":7547},{"style":143},[7548],{"type":35,"value":146},{"type":26,"tag":130,"props":7550,"children":7551},{"style":137},[7552],{"type":35,"value":7553}," repository;\n",{"type":26,"tag":130,"props":7555,"children":7556},{"class":132,"line":374},[7557],{"type":26,"tag":130,"props":7558,"children":7559},{"style":137},[7560],{"type":35,"value":3962},{"type":26,"tag":130,"props":7562,"children":7563},{"class":132,"line":1353},[7564],{"type":26,"tag":130,"props":7565,"children":7566},{"style":137},[7567],{"type":35,"value":7335},{"type":26,"tag":130,"props":7569,"children":7570},{"class":132,"line":1361},[7571,7575,7580,7585,7590,7595],{"type":26,"tag":130,"props":7572,"children":7573},{"style":143},[7574],{"type":35,"value":3764},{"type":26,"tag":130,"props":7576,"children":7577},{"style":143},[7578],{"type":35,"value":7579}," boolean",{"type":26,"tag":130,"props":7581,"children":7582},{"style":154},[7583],{"type":35,"value":7584}," registerUser",{"type":26,"tag":130,"props":7586,"children":7587},{"style":137},[7588],{"type":35,"value":7589},"(User ",{"type":26,"tag":130,"props":7591,"children":7592},{"style":3795},[7593],{"type":35,"value":7594},"user",{"type":26,"tag":130,"props":7596,"children":7597},{"style":137},[7598],{"type":35,"value":3803},{"type":26,"tag":130,"props":7600,"children":7601},{"class":132,"line":1994},[7602,7607,7612,7616],{"type":26,"tag":130,"props":7603,"children":7604},{"style":143},[7605],{"type":35,"value":7606},"        return",{"type":26,"tag":130,"props":7608,"children":7609},{"style":137},[7610],{"type":35,"value":7611}," repository.",{"type":26,"tag":130,"props":7613,"children":7614},{"style":154},[7615],{"type":35,"value":7396},{"type":26,"tag":130,"props":7617,"children":7618},{"style":137},[7619],{"type":35,"value":7620},"(user);\n",{"type":26,"tag":130,"props":7622,"children":7623},{"class":132,"line":2007},[7624],{"type":26,"tag":130,"props":7625,"children":7626},{"style":137},[7627],{"type":35,"value":3962},{"type":26,"tag":130,"props":7629,"children":7630},{"class":132,"line":2020},[7631],{"type":26,"tag":130,"props":7632,"children":7633},{"style":137},[7634],{"type":35,"value":380},{"type":26,"tag":31,"props":7636,"children":7637},{},[7638],{"type":35,"value":7639},"Finally, we refactor the code if necessary while ensuring all tests continue to pass.",{"type":26,"tag":38,"props":7641,"children":7642},{"id":879},[7643],{"type":35,"value":882},{"type":26,"tag":31,"props":7645,"children":7646},{},[7647],{"type":35,"value":7648},"Using TDD alongside tools like JUnit and Mockito not only improves software quality but also plays a crucial role in technical interviews. Many companies seek developers who understand and apply automated testing, as it ensures robust and maintainable code. Practicing TDD can set you apart in your next interview and enhance your career as a Java developer.",{"type":26,"tag":38,"props":7650,"children":7651},{"id":891},[7652],{"type":35,"value":894},{"type":26,"tag":31,"props":7654,"children":7655},{},[7656],{"type":35,"value":7657},"To deepen your understanding of TDD, JUnit, and Mockito, consider exploring the following resources:",{"type":26,"tag":896,"props":7659,"children":7660},{},[7661,7671,7681],{"type":26,"tag":54,"props":7662,"children":7663},{},[7664],{"type":26,"tag":903,"props":7665,"children":7668},{"href":7666,"rel":7667},"https://junit.org/junit5/docs/current/user-guide/",[907],[7669],{"type":35,"value":7670},"JUnit 5 User Guide",{"type":26,"tag":54,"props":7672,"children":7673},{},[7674],{"type":26,"tag":903,"props":7675,"children":7678},{"href":7676,"rel":7677},"https://site.mockito.org/",[907],[7679],{"type":35,"value":7680},"Mockito Documentation",{"type":26,"tag":54,"props":7682,"children":7683},{},[7684],{"type":26,"tag":903,"props":7685,"children":7688},{"href":7686,"rel":7687},"https://www.oreilly.com/library/view/test-driven-development/0321146530/",[907],[7689],{"type":35,"value":7690},"Test-Driven Development by Example - Kent Beck",{"type":26,"tag":31,"props":7692,"children":7693},{},[7694],{"type":35,"value":7695},"Mastering TDD will not only improve your coding skills but also help you build more reliable and maintainable software systems.",{"type":26,"tag":932,"props":7697,"children":7698},{},[7699],{"type":35,"value":936},{"title":8,"searchDepth":176,"depth":176,"links":7701},[7702,7703,7704,7705,7706],{"id":6712,"depth":176,"text":6715},{"id":6746,"depth":176,"text":6749},{"id":7236,"depth":176,"text":7239},{"id":879,"depth":176,"text":882},{"id":891,"depth":176,"text":894},"content:posts:tdd-testing.md","posts/tdd-testing.md","posts/tdd-testing",{"_path":7711,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":7712,"description":7713,"date":7714,"layout":12,"subtitle":7715,"image":7716,"optimized_image":7716,"category":15,"tags":7717,"author":21,"paginate":7,"body":7718,"_type":949,"_id":8101,"_source":951,"_file":8102,"_stem":8103,"_extension":954},"/posts/java-17","Exploring Java 17's New Features","Exploring Java 17's New Features with examples","2023-10-08T11:00:00.000Z","with examples","/assets/img/uploads/java-source-code.png",[15,17],{"type":23,"children":7719,"toc":8093},[7720,7725,7730,7736,7741,7809,7813,7818,7889,7895,7900,8053,8059,8064,8070,8075,8079,8084,8089],{"type":26,"tag":31,"props":7721,"children":7722},{},[7723],{"type":35,"value":7724},"Java 17 is here, and it brings along a host of exciting features that enhance the language's capabilities. In this post, we'll dive into some of the key additions and provide practical code examples to help you get started.",{"type":26,"tag":31,"props":7726,"children":7727},{},[7728],{"type":35,"value":7729},"Java 17, a long-term support (LTS) release, introduces several noteworthy features that simplify coding and improve performance. Let's explore these features one by one.",{"type":26,"tag":1062,"props":7731,"children":7733},{"id":7732},"pattern-matching-for-instanceof-operator",[7734],{"type":35,"value":7735},"Pattern Matching for instanceof operator",{"type":26,"tag":31,"props":7737,"children":7738},{},[7739],{"type":35,"value":7740},"Pattern Matching is a game-changer in Java 17. It allows you to combine type checking and type casting in a single line, making your code more concise and readable. Here's an example:",{"type":26,"tag":121,"props":7742,"children":7744},{"className":123,"code":7743,"language":17,"meta":8,"style":8},"if (object instanceof String str) {\n    // 'str' is now of type String within this block\n    System.out.println(str.length());\n}\n",[7745],{"type":26,"tag":15,"props":7746,"children":7747},{"__ignoreMap":8},[7748,7769,7777,7802],{"type":26,"tag":130,"props":7749,"children":7750},{"class":132,"line":133},[7751,7755,7760,7764],{"type":26,"tag":130,"props":7752,"children":7753},{"style":143},[7754],{"type":35,"value":346},{"type":26,"tag":130,"props":7756,"children":7757},{"style":137},[7758],{"type":35,"value":7759}," (object ",{"type":26,"tag":130,"props":7761,"children":7762},{"style":143},[7763],{"type":35,"value":2913},{"type":26,"tag":130,"props":7765,"children":7766},{"style":137},[7767],{"type":35,"value":7768}," String str) {\n",{"type":26,"tag":130,"props":7770,"children":7771},{"class":132,"line":176},[7772],{"type":26,"tag":130,"props":7773,"children":7774},{"style":368},[7775],{"type":35,"value":7776},"    // 'str' is now of type String within this block\n",{"type":26,"tag":130,"props":7778,"children":7779},{"class":132,"line":205},[7780,7784,7788,7793,7798],{"type":26,"tag":130,"props":7781,"children":7782},{"style":137},[7783],{"type":35,"value":2943},{"type":26,"tag":130,"props":7785,"children":7786},{"style":154},[7787],{"type":35,"value":1554},{"type":26,"tag":130,"props":7789,"children":7790},{"style":137},[7791],{"type":35,"value":7792},"(str.",{"type":26,"tag":130,"props":7794,"children":7795},{"style":154},[7796],{"type":35,"value":7797},"length",{"type":26,"tag":130,"props":7799,"children":7800},{"style":137},[7801],{"type":35,"value":338},{"type":26,"tag":130,"props":7803,"children":7804},{"class":132,"line":231},[7805],{"type":26,"tag":130,"props":7806,"children":7807},{"style":137},[7808],{"type":35,"value":380},{"type":26,"tag":1062,"props":7810,"children":7811},{"id":2811},[7812],{"type":35,"value":3169},{"type":26,"tag":31,"props":7814,"children":7815},{},[7816],{"type":35,"value":7817},"Sealed classes enable you to restrict which classes can be subclasses. This promotes better control over your code's architecture. Here's how you can define a sealed class:",{"type":26,"tag":121,"props":7819,"children":7821},{"className":123,"code":7820,"language":17,"meta":8,"style":8},"public sealed class Shape permits Circle, Rectangle, Triangle {\n// Class definition here\n}\n",[7822],{"type":26,"tag":15,"props":7823,"children":7824},{"__ignoreMap":8},[7825,7874,7882],{"type":26,"tag":130,"props":7826,"children":7827},{"class":132,"line":133},[7828,7832,7836,7840,7844,7849,7853,7857,7861,7865,7870],{"type":26,"tag":130,"props":7829,"children":7830},{"style":143},[7831],{"type":35,"value":3195},{"type":26,"tag":130,"props":7833,"children":7834},{"style":143},[7835],{"type":35,"value":3200},{"type":26,"tag":130,"props":7837,"children":7838},{"style":143},[7839],{"type":35,"value":3210},{"type":26,"tag":130,"props":7841,"children":7842},{"style":154},[7843],{"type":35,"value":3280},{"type":26,"tag":130,"props":7845,"children":7846},{"style":143},[7847],{"type":35,"value":7848}," permits",{"type":26,"tag":130,"props":7850,"children":7851},{"style":154},[7852],{"type":35,"value":3228},{"type":26,"tag":130,"props":7854,"children":7855},{"style":137},[7856],{"type":35,"value":3233},{"type":26,"tag":130,"props":7858,"children":7859},{"style":154},[7860],{"type":35,"value":3238},{"type":26,"tag":130,"props":7862,"children":7863},{"style":137},[7864],{"type":35,"value":3233},{"type":26,"tag":130,"props":7866,"children":7867},{"style":154},[7868],{"type":35,"value":7869},"Triangle",{"type":26,"tag":130,"props":7871,"children":7872},{"style":137},[7873],{"type":35,"value":3285},{"type":26,"tag":130,"props":7875,"children":7876},{"class":132,"line":176},[7877],{"type":26,"tag":130,"props":7878,"children":7879},{"style":368},[7880],{"type":35,"value":7881},"// Class definition here\n",{"type":26,"tag":130,"props":7883,"children":7884},{"class":132,"line":205},[7885],{"type":26,"tag":130,"props":7886,"children":7887},{"style":137},[7888],{"type":35,"value":380},{"type":26,"tag":1062,"props":7890,"children":7892},{"id":7891},"new-switch-expressions",[7893],{"type":35,"value":7894},"New Switch Expressions",{"type":26,"tag":31,"props":7896,"children":7897},{},[7898],{"type":35,"value":7899},"Java 17 enhances switch expressions by allowing you to simplify repetitive code. Now, you can use \"case ->\" syntax to create more concise switch expressions:",{"type":26,"tag":121,"props":7901,"children":7903},{"className":123,"code":7902,"language":17,"meta":8,"style":8},"int day = 3;\nString dayName = switch (day) {\n    case 1 -> \"Monday\";\n    case 2 -> \"Tuesday\";\n    case 3 -> \"Wednesday\";\n    default -> \"Unknown\";\n};\n",[7904],{"type":26,"tag":15,"props":7905,"children":7906},{"__ignoreMap":8},[7907,7932,7953,7977,8002,8026,8046],{"type":26,"tag":130,"props":7908,"children":7909},{"class":132,"line":133},[7910,7914,7919,7923,7928],{"type":26,"tag":130,"props":7911,"children":7912},{"style":143},[7913],{"type":35,"value":6037},{"type":26,"tag":130,"props":7915,"children":7916},{"style":137},[7917],{"type":35,"value":7918}," day ",{"type":26,"tag":130,"props":7920,"children":7921},{"style":143},[7922],{"type":35,"value":146},{"type":26,"tag":130,"props":7924,"children":7925},{"style":194},[7926],{"type":35,"value":7927}," 3",{"type":26,"tag":130,"props":7929,"children":7930},{"style":137},[7931],{"type":35,"value":2889},{"type":26,"tag":130,"props":7933,"children":7934},{"class":132,"line":176},[7935,7940,7944,7948],{"type":26,"tag":130,"props":7936,"children":7937},{"style":137},[7938],{"type":35,"value":7939},"String dayName ",{"type":26,"tag":130,"props":7941,"children":7942},{"style":143},[7943],{"type":35,"value":146},{"type":26,"tag":130,"props":7945,"children":7946},{"style":143},[7947],{"type":35,"value":3429},{"type":26,"tag":130,"props":7949,"children":7950},{"style":137},[7951],{"type":35,"value":7952}," (day) {\n",{"type":26,"tag":130,"props":7954,"children":7955},{"class":132,"line":205},[7956,7960,7964,7968,7973],{"type":26,"tag":130,"props":7957,"children":7958},{"style":143},[7959],{"type":35,"value":3027},{"type":26,"tag":130,"props":7961,"children":7962},{"style":194},[7963],{"type":35,"value":3095},{"type":26,"tag":130,"props":7965,"children":7966},{"style":143},[7967],{"type":35,"value":3112},{"type":26,"tag":130,"props":7969,"children":7970},{"style":165},[7971],{"type":35,"value":7972}," \"Monday\"",{"type":26,"tag":130,"props":7974,"children":7975},{"style":137},[7976],{"type":35,"value":2889},{"type":26,"tag":130,"props":7978,"children":7979},{"class":132,"line":231},[7980,7984,7989,7993,7998],{"type":26,"tag":130,"props":7981,"children":7982},{"style":143},[7983],{"type":35,"value":3027},{"type":26,"tag":130,"props":7985,"children":7986},{"style":194},[7987],{"type":35,"value":7988}," 2",{"type":26,"tag":130,"props":7990,"children":7991},{"style":143},[7992],{"type":35,"value":3112},{"type":26,"tag":130,"props":7994,"children":7995},{"style":165},[7996],{"type":35,"value":7997}," \"Tuesday\"",{"type":26,"tag":130,"props":7999,"children":8000},{"style":137},[8001],{"type":35,"value":2889},{"type":26,"tag":130,"props":8003,"children":8004},{"class":132,"line":364},[8005,8009,8013,8017,8022],{"type":26,"tag":130,"props":8006,"children":8007},{"style":143},[8008],{"type":35,"value":3027},{"type":26,"tag":130,"props":8010,"children":8011},{"style":194},[8012],{"type":35,"value":7927},{"type":26,"tag":130,"props":8014,"children":8015},{"style":143},[8016],{"type":35,"value":3112},{"type":26,"tag":130,"props":8018,"children":8019},{"style":165},[8020],{"type":35,"value":8021}," \"Wednesday\"",{"type":26,"tag":130,"props":8023,"children":8024},{"style":137},[8025],{"type":35,"value":2889},{"type":26,"tag":130,"props":8027,"children":8028},{"class":132,"line":374},[8029,8033,8037,8042],{"type":26,"tag":130,"props":8030,"children":8031},{"style":143},[8032],{"type":35,"value":3107},{"type":26,"tag":130,"props":8034,"children":8035},{"style":143},[8036],{"type":35,"value":3112},{"type":26,"tag":130,"props":8038,"children":8039},{"style":165},[8040],{"type":35,"value":8041}," \"Unknown\"",{"type":26,"tag":130,"props":8043,"children":8044},{"style":137},[8045],{"type":35,"value":2889},{"type":26,"tag":130,"props":8047,"children":8048},{"class":132,"line":1353},[8049],{"type":26,"tag":130,"props":8050,"children":8051},{"style":137},[8052],{"type":35,"value":3512},{"type":26,"tag":1062,"props":8054,"children":8056},{"id":8055},"strong-encapsulation-of-jdk-internals",[8057],{"type":35,"value":8058},"Strong Encapsulation of JDK Internals",{"type":26,"tag":31,"props":8060,"children":8061},{},[8062],{"type":35,"value":8063},"With strong encapsulation, Java 17 further restricts access to JDK internals, promoting better security and stability of your applications.",{"type":26,"tag":1062,"props":8065,"children":8067},{"id":8066},"foreign-function-memory-api",[8068],{"type":35,"value":8069},"Foreign Function & Memory API",{"type":26,"tag":31,"props":8071,"children":8072},{},[8073],{"type":35,"value":8074},"Java 17 introduces a Foreign Function & Memory API that facilitates interaction with native code and memory management. This is especially valuable for low-level operations.",{"type":26,"tag":1062,"props":8076,"children":8077},{"id":879},[8078],{"type":35,"value":882},{"type":26,"tag":31,"props":8080,"children":8081},{},[8082],{"type":35,"value":8083},"Java 17 brings a wealth of new features that make coding in Java more efficient and secure. Pattern matching, sealed classes, improved switch expressions, and stronger encapsulation are just a few of the highlights. These additions not only simplify your code but also enhance its performance and maintainability.",{"type":26,"tag":31,"props":8085,"children":8086},{},[8087],{"type":35,"value":8088},"Start exploring these features today and take your Java development skills to the next level!",{"type":26,"tag":932,"props":8090,"children":8091},{},[8092],{"type":35,"value":936},{"title":8,"searchDepth":176,"depth":176,"links":8094},[8095,8096,8097,8098,8099,8100],{"id":7732,"depth":205,"text":7735},{"id":2811,"depth":205,"text":3169},{"id":7891,"depth":205,"text":7894},{"id":8055,"depth":205,"text":8058},{"id":8066,"depth":205,"text":8069},{"id":879,"depth":205,"text":882},"content:posts:java-17.md","posts/java-17.md","posts/java-17",{"_path":8105,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":8106,"description":8106,"date":8107,"layout":12,"subtitle":8108,"image":8109,"optimized_image":8109,"category":15,"tags":8110,"author":21,"paginate":7,"body":8112,"_type":949,"_id":8735,"_source":951,"_file":8736,"_stem":8737,"_extension":954},"/posts/hexagonal-architecture","Introduction to Hexagonal Architecture","2023-10-02 18:00:00","A brief introduction","/assets/img/uploads/hexagonal-architecture.jpeg",[15,17,8111],"architecture",{"type":23,"children":8113,"toc":8725},[8114,8119,8125,8144,8149,8172,8177,8189,8204,8210,8215,8268,8274,8279,8285,8290,8313,8318,8324,8329,8352,8357,8363,8368,8593,8598,8669,8674,8678,8683,8716,8721],{"type":26,"tag":31,"props":8115,"children":8116},{},[8117],{"type":35,"value":8118},"In the world of software development, architectural patterns play a pivotal role in creating robust, maintainable, and flexible systems. One such architectural pattern that has gained popularity in recent years is Hexagonal Architecture. In this article, we will delve into the fundamentals of Hexagonal Architecture, explore its advantages, and illustrate how to structure packages in a Java project following this architectural style.",{"type":26,"tag":38,"props":8120,"children":8122},{"id":8121},"what-is-hexagonal-architecture",[8123],{"type":35,"value":8124},"What is Hexagonal Architecture?",{"type":26,"tag":31,"props":8126,"children":8127},{},[8128,8130,8135,8137,8142],{"type":35,"value":8129},"Hexagonal Architecture, also known as ",{"type":26,"tag":994,"props":8131,"children":8132},{},[8133],{"type":35,"value":8134},"Ports and Adapters",{"type":35,"value":8136}," or the ",{"type":26,"tag":994,"props":8138,"children":8139},{},[8140],{"type":35,"value":8141},"Onion Architecture",{"type":35,"value":8143},", is a design pattern that promotes the separation of concerns and modularization in software systems. It was first introduced by Alistair Cockburn in 2005. At its core, Hexagonal Architecture revolves around the idea of isolating the core business logic from external dependencies and infrastructure concerns.",{"type":26,"tag":31,"props":8145,"children":8146},{},[8147],{"type":35,"value":8148},"The central concept of Hexagonal Architecture is the division of an application into two main parts:",{"type":26,"tag":50,"props":8150,"children":8151},{},[8152,8162],{"type":26,"tag":54,"props":8153,"children":8154},{},[8155,8160],{"type":26,"tag":994,"props":8156,"children":8157},{},[8158],{"type":35,"value":8159},"Core Business Logic",{"type":35,"value":8161},": This is the heart of the application where the domain-specific rules and functionality reside. It should be completely isolated from any external factors like databases, user interfaces, or third-party services.",{"type":26,"tag":54,"props":8163,"children":8164},{},[8165,8170],{"type":26,"tag":994,"props":8166,"children":8167},{},[8168],{"type":35,"value":8169},"External Interfaces",{"type":35,"value":8171},": These are the entry points and exit points to the application. They include adapters that communicate with the external world, such as REST APIs, databases, UI frameworks, and messaging systems.",{"type":26,"tag":31,"props":8173,"children":8174},{},[8175],{"type":35,"value":8176},"The goal of Hexagonal Architecture is to ensure that changes in the external interfaces (adapters) do not impact the core business logic, and vice versa. This separation enables better testability, maintainability, and scalability of your software.",{"type":26,"tag":31,"props":8178,"children":8179},{},[8180,8185],{"type":26,"tag":8181,"props":8182,"children":8184},"img",{"alt":8,"src":8183},"https://miro.medium.com/v2/resize:fit:1400/format:webp/1*ebUHgG6JwawEifXlARgfzg.png",[],{"type":26,"tag":8186,"props":8187,"children":8188},"em",{},[],{"type":26,"tag":8190,"props":8191,"children":8192},"center",{},[8193],{"type":26,"tag":8186,"props":8194,"children":8195},{},[8196,8198],{"type":35,"value":8197},"source: ",{"type":26,"tag":903,"props":8199,"children":8201},{"href":8200},"https://blog.devgenius.io/flask-blog-tutorial-with-hexagonal-architecture-part-1-6446e7e9aaaa",[8202],{"type":35,"value":8203}," medium.com",{"type":26,"tag":38,"props":8205,"children":8207},{"id":8206},"advantages-of-hexagonal-architecture",[8208],{"type":35,"value":8209},"Advantages of Hexagonal Architecture",{"type":26,"tag":31,"props":8211,"children":8212},{},[8213],{"type":35,"value":8214},"Utilizing Hexagonal Architecture offers several advantages:",{"type":26,"tag":50,"props":8216,"children":8217},{},[8218,8228,8238,8248,8258],{"type":26,"tag":54,"props":8219,"children":8220},{},[8221,8226],{"type":26,"tag":994,"props":8222,"children":8223},{},[8224],{"type":35,"value":8225},"Modularity",{"type":35,"value":8227},": The separation of concerns into core business logic and external interfaces makes it easier to maintain and extend your application. Changes in one part of the system have minimal impact on the other.",{"type":26,"tag":54,"props":8229,"children":8230},{},[8231,8236],{"type":26,"tag":994,"props":8232,"children":8233},{},[8234],{"type":35,"value":8235},"Testability",{"type":35,"value":8237},": Isolating the core logic allows for comprehensive unit testing without the need for complex mocking of external dependencies.",{"type":26,"tag":54,"props":8239,"children":8240},{},[8241,8246],{"type":26,"tag":994,"props":8242,"children":8243},{},[8244],{"type":35,"value":8245},"Flexibility",{"type":35,"value":8247},": You can switch out external components (e.g., databases, UI frameworks) without affecting the core business logic. This adaptability is particularly beneficial when upgrading or changing technology stacks.",{"type":26,"tag":54,"props":8249,"children":8250},{},[8251,8256],{"type":26,"tag":994,"props":8252,"children":8253},{},[8254],{"type":35,"value":8255},"Clean Code",{"type":35,"value":8257},": Hexagonal Architecture encourages clean and organized code. It promotes the use of interfaces and clear boundaries between components, making the codebase more understandable.",{"type":26,"tag":54,"props":8259,"children":8260},{},[8261,8266],{"type":26,"tag":994,"props":8262,"children":8263},{},[8264],{"type":35,"value":8265},"Business Focus",{"type":35,"value":8267},": Developers can focus on implementing business requirements without being distracted by technical details, resulting in a more business-centric codebase.",{"type":26,"tag":38,"props":8269,"children":8271},{"id":8270},"ports-and-adapters-in-hexagonal-architecture",[8272],{"type":35,"value":8273},"Ports and Adapters in Hexagonal Architecture",{"type":26,"tag":31,"props":8275,"children":8276},{},[8277],{"type":35,"value":8278},"In Hexagonal Architecture, the concepts of \"Ports\" and \"Adapters\" play a central role in achieving its architectural goals. Let's take a closer look at what these terms mean:",{"type":26,"tag":1062,"props":8280,"children":8282},{"id":8281},"ports",[8283],{"type":35,"value":8284},"Ports",{"type":26,"tag":31,"props":8286,"children":8287},{},[8288],{"type":35,"value":8289},"Ports are interfaces or contracts that define the interactions between the core business logic of your application and the external world. They represent the entry points and exit points for data and functionality. In simpler terms, ports are the \"what\" your application needs from the outside world.",{"type":26,"tag":896,"props":8291,"children":8292},{},[8293,8303],{"type":26,"tag":54,"props":8294,"children":8295},{},[8296,8301],{"type":26,"tag":994,"props":8297,"children":8298},{},[8299],{"type":35,"value":8300},"Primary Ports (Inbound)",{"type":35,"value":8302},": These are entry points for external interactions with your application. Examples include REST API endpoints, command handlers, or event listeners.",{"type":26,"tag":54,"props":8304,"children":8305},{},[8306,8311],{"type":26,"tag":994,"props":8307,"children":8308},{},[8309],{"type":35,"value":8310},"Secondary Ports (Outbound)",{"type":35,"value":8312},": These are exit points through which your application interacts with external resources, such as databases, external services, or message queues. They define what your application provides to the external world.",{"type":26,"tag":31,"props":8314,"children":8315},{},[8316],{"type":35,"value":8317},"Ports are defined as Java interfaces, for example, in the context of Spring Boot, they can be defined as Spring beans, ensuring that the core business logic interacts with the external world through these well-defined interfaces.",{"type":26,"tag":1062,"props":8319,"children":8321},{"id":8320},"adapters",[8322],{"type":35,"value":8323},"Adapters",{"type":26,"tag":31,"props":8325,"children":8326},{},[8327],{"type":35,"value":8328},"Adapters, on the other hand, are responsible for implementing the ports and enabling communication between the core business logic and external resources. Adapters bridge the gap between the application's internal interfaces (ports) and the external technologies and systems.",{"type":26,"tag":896,"props":8330,"children":8331},{},[8332,8342],{"type":26,"tag":54,"props":8333,"children":8334},{},[8335,8340],{"type":26,"tag":994,"props":8336,"children":8337},{},[8338],{"type":35,"value":8339},"Primary Adapters (Inbound)",{"type":35,"value":8341},": These are implementations of the primary ports, allowing external systems to communicate with your application. For example, a REST controller that handles HTTP requests and routes them to the application's use cases.",{"type":26,"tag":54,"props":8343,"children":8344},{},[8345,8350],{"type":26,"tag":994,"props":8346,"children":8347},{},[8348],{"type":35,"value":8349},"Secondary Adapters (Outbound)",{"type":35,"value":8351},": These are implementations of the secondary ports, facilitating communication between your application and external resources. This could include database repositories, external API clients, or message queue consumers.",{"type":26,"tag":31,"props":8353,"children":8354},{},[8355],{"type":35,"value":8356},"Adapters are responsible for translating external input into a format understandable by the core business logic and vice versa. They ensure that the application remains isolated from the specifics of the external technologies it interacts with.",{"type":26,"tag":38,"props":8358,"children":8360},{"id":8359},"structuring-a-spring-boot-project-with-hexagonal-architecture",[8361],{"type":35,"value":8362},"Structuring a Spring Boot Project with Hexagonal Architecture",{"type":26,"tag":31,"props":8364,"children":8365},{},[8366],{"type":35,"value":8367},"Now, let's explore how you can structure a Java (Spring Boot) project using Hexagonal Architecture. Here's an example structure:",{"type":26,"tag":121,"props":8369,"children":8373},{"className":8370,"code":8371,"language":8372,"meta":8,"style":8},"language-css shiki shiki-themes github-dark github-light","myapp/\n├── src/\n│   ├── main/\n│   │   ├── java/\n│   │   │   ├── com/\n│   │   │   │   ├── myapp/\n│   │   │   │   │   ├── application/\n│   │   │   │   │   │   ├── MyApplication.java\n│   │   │   │   │   │   └── ...\n│   │   │   │   │   ├── domain/\n│   │   │   │   │   │   ├── MyEntity.java\n│   │   │   │   │   │   └── ...\n│   │   │   │   │   ├── ports/\n│   │   │   │   │   │   ├── MyRepository.java\n│   │   │   │   │   │   └── ...\n│   │   │   │   │   └── ...\n│   │   │   │   ├── infrastructure/\n│   │   │   │   │   ├── adapter/\n│   │   │   │   │   │   ├── MyRepositoryImpl.java\n│   │   │   │   │   │   └── ...\n│   │   │   │   │   ├── web/\n│   │   │   │   │   │   ├── MyController.java\n│   │   │   │   │   │   └── ...\n│   │   │   │   │   └── ...\n│   ├── resources/\n│   └── ...\n└── ...\n","css",[8374],{"type":26,"tag":15,"props":8375,"children":8376},{"__ignoreMap":8},[8377,8385,8393,8401,8409,8417,8425,8433,8441,8449,8457,8465,8472,8480,8488,8495,8503,8511,8519,8527,8534,8542,8550,8558,8566,8575,8584],{"type":26,"tag":130,"props":8378,"children":8379},{"class":132,"line":133},[8380],{"type":26,"tag":130,"props":8381,"children":8382},{},[8383],{"type":35,"value":8384},"myapp/\n",{"type":26,"tag":130,"props":8386,"children":8387},{"class":132,"line":176},[8388],{"type":26,"tag":130,"props":8389,"children":8390},{},[8391],{"type":35,"value":8392},"├── src/\n",{"type":26,"tag":130,"props":8394,"children":8395},{"class":132,"line":205},[8396],{"type":26,"tag":130,"props":8397,"children":8398},{},[8399],{"type":35,"value":8400},"│   ├── main/\n",{"type":26,"tag":130,"props":8402,"children":8403},{"class":132,"line":231},[8404],{"type":26,"tag":130,"props":8405,"children":8406},{},[8407],{"type":35,"value":8408},"│   │   ├── java/\n",{"type":26,"tag":130,"props":8410,"children":8411},{"class":132,"line":364},[8412],{"type":26,"tag":130,"props":8413,"children":8414},{},[8415],{"type":35,"value":8416},"│   │   │   ├── com/\n",{"type":26,"tag":130,"props":8418,"children":8419},{"class":132,"line":374},[8420],{"type":26,"tag":130,"props":8421,"children":8422},{},[8423],{"type":35,"value":8424},"│   │   │   │   ├── myapp/\n",{"type":26,"tag":130,"props":8426,"children":8427},{"class":132,"line":1353},[8428],{"type":26,"tag":130,"props":8429,"children":8430},{},[8431],{"type":35,"value":8432},"│   │   │   │   │   ├── application/\n",{"type":26,"tag":130,"props":8434,"children":8435},{"class":132,"line":1361},[8436],{"type":26,"tag":130,"props":8437,"children":8438},{},[8439],{"type":35,"value":8440},"│   │   │   │   │   │   ├── MyApplication.java\n",{"type":26,"tag":130,"props":8442,"children":8443},{"class":132,"line":1994},[8444],{"type":26,"tag":130,"props":8445,"children":8446},{},[8447],{"type":35,"value":8448},"│   │   │   │   │   │   └── ...\n",{"type":26,"tag":130,"props":8450,"children":8451},{"class":132,"line":2007},[8452],{"type":26,"tag":130,"props":8453,"children":8454},{},[8455],{"type":35,"value":8456},"│   │   │   │   │   ├── domain/\n",{"type":26,"tag":130,"props":8458,"children":8459},{"class":132,"line":2020},[8460],{"type":26,"tag":130,"props":8461,"children":8462},{},[8463],{"type":35,"value":8464},"│   │   │   │   │   │   ├── MyEntity.java\n",{"type":26,"tag":130,"props":8466,"children":8467},{"class":132,"line":2038},[8468],{"type":26,"tag":130,"props":8469,"children":8470},{},[8471],{"type":35,"value":8448},{"type":26,"tag":130,"props":8473,"children":8474},{"class":132,"line":2046},[8475],{"type":26,"tag":130,"props":8476,"children":8477},{},[8478],{"type":35,"value":8479},"│   │   │   │   │   ├── ports/\n",{"type":26,"tag":130,"props":8481,"children":8482},{"class":132,"line":2059},[8483],{"type":26,"tag":130,"props":8484,"children":8485},{},[8486],{"type":35,"value":8487},"│   │   │   │   │   │   ├── MyRepository.java\n",{"type":26,"tag":130,"props":8489,"children":8490},{"class":132,"line":2082},[8491],{"type":26,"tag":130,"props":8492,"children":8493},{},[8494],{"type":35,"value":8448},{"type":26,"tag":130,"props":8496,"children":8497},{"class":132,"line":2103},[8498],{"type":26,"tag":130,"props":8499,"children":8500},{},[8501],{"type":35,"value":8502},"│   │   │   │   │   └── ...\n",{"type":26,"tag":130,"props":8504,"children":8505},{"class":132,"line":2121},[8506],{"type":26,"tag":130,"props":8507,"children":8508},{},[8509],{"type":35,"value":8510},"│   │   │   │   ├── infrastructure/\n",{"type":26,"tag":130,"props":8512,"children":8513},{"class":132,"line":2134},[8514],{"type":26,"tag":130,"props":8515,"children":8516},{},[8517],{"type":35,"value":8518},"│   │   │   │   │   ├── adapter/\n",{"type":26,"tag":130,"props":8520,"children":8521},{"class":132,"line":2152},[8522],{"type":26,"tag":130,"props":8523,"children":8524},{},[8525],{"type":35,"value":8526},"│   │   │   │   │   │   ├── MyRepositoryImpl.java\n",{"type":26,"tag":130,"props":8528,"children":8529},{"class":132,"line":2170},[8530],{"type":26,"tag":130,"props":8531,"children":8532},{},[8533],{"type":35,"value":8448},{"type":26,"tag":130,"props":8535,"children":8536},{"class":132,"line":2178},[8537],{"type":26,"tag":130,"props":8538,"children":8539},{},[8540],{"type":35,"value":8541},"│   │   │   │   │   ├── web/\n",{"type":26,"tag":130,"props":8543,"children":8544},{"class":132,"line":2199},[8545],{"type":26,"tag":130,"props":8546,"children":8547},{},[8548],{"type":35,"value":8549},"│   │   │   │   │   │   ├── MyController.java\n",{"type":26,"tag":130,"props":8551,"children":8553},{"class":132,"line":8552},23,[8554],{"type":26,"tag":130,"props":8555,"children":8556},{},[8557],{"type":35,"value":8448},{"type":26,"tag":130,"props":8559,"children":8561},{"class":132,"line":8560},24,[8562],{"type":26,"tag":130,"props":8563,"children":8564},{},[8565],{"type":35,"value":8502},{"type":26,"tag":130,"props":8567,"children":8569},{"class":132,"line":8568},25,[8570],{"type":26,"tag":130,"props":8571,"children":8572},{},[8573],{"type":35,"value":8574},"│   ├── resources/\n",{"type":26,"tag":130,"props":8576,"children":8578},{"class":132,"line":8577},26,[8579],{"type":26,"tag":130,"props":8580,"children":8581},{},[8582],{"type":35,"value":8583},"│   └── ...\n",{"type":26,"tag":130,"props":8585,"children":8587},{"class":132,"line":8586},27,[8588],{"type":26,"tag":130,"props":8589,"children":8590},{},[8591],{"type":35,"value":8592},"└── ...\n",{"type":26,"tag":31,"props":8594,"children":8595},{},[8596],{"type":35,"value":8597},"In this structure:",{"type":26,"tag":896,"props":8599,"children":8600},{},[8601,8612,8623,8633],{"type":26,"tag":54,"props":8602,"children":8603},{},[8604,8610],{"type":26,"tag":15,"props":8605,"children":8607},{"className":8606},[],[8608],{"type":35,"value":8609},"application",{"type":35,"value":8611},": Contains use cases and application services that orchestrate the core business logic.",{"type":26,"tag":54,"props":8613,"children":8614},{},[8615,8621],{"type":26,"tag":15,"props":8616,"children":8618},{"className":8617},[],[8619],{"type":35,"value":8620},"domain",{"type":35,"value":8622},": Holds the domain model, including entities, value objects, and domain-specific logic.",{"type":26,"tag":54,"props":8624,"children":8625},{},[8626,8631],{"type":26,"tag":15,"props":8627,"children":8629},{"className":8628},[],[8630],{"type":35,"value":8281},{"type":35,"value":8632},": Defines interfaces (ports) that the core business logic requires from external dependencies. Implementations of these interfaces are provided in the infrastructure package.",{"type":26,"tag":54,"props":8634,"children":8635},{},[8636,8642,8644],{"type":26,"tag":15,"props":8637,"children":8639},{"className":8638},[],[8640],{"type":35,"value":8641},"infrastructure",{"type":35,"value":8643},": Contains external adapters and implementations.",{"type":26,"tag":896,"props":8645,"children":8646},{},[8647,8658],{"type":26,"tag":54,"props":8648,"children":8649},{},[8650,8656],{"type":26,"tag":15,"props":8651,"children":8653},{"className":8652},[],[8654],{"type":35,"value":8655},"adapter",{"type":35,"value":8657},": Houses adapters that connect the application to external resources such as databases or message queues. For example, MyRepositoryImpl implements the MyRepository interface.",{"type":26,"tag":54,"props":8659,"children":8660},{},[8661,8667],{"type":26,"tag":15,"props":8662,"children":8664},{"className":8663},[],[8665],{"type":35,"value":8666},"web",{"type":35,"value":8668},": This is where you define your REST API controllers. MyController represents a RESTful API controller.",{"type":26,"tag":31,"props":8670,"children":8671},{},[8672],{"type":35,"value":8673},"With this structure, you maintain a clear separation between the core business logic (inside the application and domain packages) and the external interfaces (inside the infrastructure and web packages). This promotes testability, maintainability, and scalability while allowing you to leverage the Spring Boot framework for building RESTful APIs.",{"type":26,"tag":38,"props":8675,"children":8676},{"id":891},[8677],{"type":35,"value":894},{"type":26,"tag":31,"props":8679,"children":8680},{},[8681],{"type":35,"value":8682},"If you're interested in diving deeper into Hexagonal Architecture and its application in Spring Boot projects, here are some valuable resources to explore:",{"type":26,"tag":896,"props":8684,"children":8685},{},[8686,8701],{"type":26,"tag":54,"props":8687,"children":8688},{},[8689,8699],{"type":26,"tag":994,"props":8690,"children":8691},{},[8692],{"type":26,"tag":903,"props":8693,"children":8696},{"href":8694,"rel":8695},"https://alistair.cockburn.us/hexagonal-architecture/",[907],[8697],{"type":35,"value":8698},"Hexagonal Architecture by Alistair Cockburn",{"type":35,"value":8700},": The original article by Alistair Cockburn, the creator of Hexagonal Architecture, provides an in-depth explanation of the concept.",{"type":26,"tag":54,"props":8702,"children":8703},{},[8704,8714],{"type":26,"tag":994,"props":8705,"children":8706},{},[8707],{"type":26,"tag":903,"props":8708,"children":8711},{"href":8709,"rel":8710},"https://www.oreilly.com/library/view/clean-architecture-a/9780134494272/",[907],[8712],{"type":35,"value":8713},"Clean Architecture by Robert C. Martin",{"type":35,"value":8715},": Although not strictly Hexagonal Architecture, Clean Architecture shares similar principles and is worth exploring for a broader perspective on architectural patterns.",{"type":26,"tag":31,"props":8717,"children":8718},{},[8719],{"type":35,"value":8720},"These resources will provide you with a solid foundation and practical insights into Hexagonal Architecture, helping you design and build well-structured and maintainable software applications.",{"type":26,"tag":932,"props":8722,"children":8723},{},[8724],{"type":35,"value":936},{"title":8,"searchDepth":176,"depth":176,"links":8726},[8727,8728,8729,8733,8734],{"id":8121,"depth":176,"text":8124},{"id":8206,"depth":176,"text":8209},{"id":8270,"depth":176,"text":8273,"children":8730},[8731,8732],{"id":8281,"depth":205,"text":8284},{"id":8320,"depth":205,"text":8323},{"id":8359,"depth":176,"text":8362},{"id":891,"depth":176,"text":894},"content:posts:hexagonal-architecture.md","posts/hexagonal-architecture.md","posts/hexagonal-architecture",{"_path":8739,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":8740,"description":8741,"date":8742,"layout":12,"subtitle":8741,"image":8743,"optimized_image":8743,"category":8641,"tags":8744,"author":21,"paginate":7,"body":8747,"_type":949,"_id":10646,"_source":951,"_file":10647,"_stem":10648,"_extension":954},"/posts/manage-aws-infrastructure-with-terraform","Bootstrap complete Java application infrastructure in AWS with Terraform","How to bootstrap a Java + MySql application infrastructure with terraform","2020-12-02T11:00:00.000Z","/assets/img/uploads/infrastructure.jpg",[8745,8746,17],"terraform","aws",{"type":23,"children":8748,"toc":10639},[8749,8759,8765,8770,8779,8785,8790,8823,8828,9232,9238,9243,9665,9671,9683,10577,10583,10588,10617,10635],{"type":26,"tag":31,"props":8750,"children":8751},{},[8752,8757],{"type":26,"tag":994,"props":8753,"children":8754},{},[8755],{"type":35,"value":8756},"Terraform",{"type":35,"value":8758}," provides a way of describe infrastructure as code. Terraform will manage the communication with the\ninfrastructure provider (Amazon AWS in this example) to create, update or delete infrastructure resources.",{"type":26,"tag":38,"props":8760,"children":8762},{"id":8761},"bootstrap-elasticbeanstalk-rds-mysql-application",[8763],{"type":35,"value":8764},"Bootstrap ElasticBeanstalk + RDS MySql application",{"type":26,"tag":31,"props":8766,"children":8767},{},[8768],{"type":35,"value":8769},"In the following example we are going to bootstrap the necessary infrastructure to serve a Java API connected to RDS\nMySql database.",{"type":26,"tag":31,"props":8771,"children":8772},{},[8773],{"type":26,"tag":8181,"props":8774,"children":8778},{"alt":8775,"src":8776,"title":8777},"aws infrastructure diagram","/assets/img/uploads/terraform-basic.png","Aws infrastructure diagram",[],{"type":26,"tag":38,"props":8780,"children":8782},{"id":8781},"step-1-networking",[8783],{"type":35,"value":8784},"Step 1 - Networking",{"type":26,"tag":31,"props":8786,"children":8787},{},[8788],{"type":35,"value":8789},"We are going to create a terraform module for VPC and other networking resources:",{"type":26,"tag":896,"props":8791,"children":8792},{},[8793,8803,8813],{"type":26,"tag":54,"props":8794,"children":8795},{},[8796,8801],{"type":26,"tag":994,"props":8797,"children":8798},{},[8799],{"type":35,"value":8800},"VPC",{"type":35,"value":8802}," - Virtual Private Cloud: Is a logical group of resources that are isolated from other VPCs and other customers\nof the Public Cloud.",{"type":26,"tag":54,"props":8804,"children":8805},{},[8806,8811],{"type":26,"tag":994,"props":8807,"children":8808},{},[8809],{"type":35,"value":8810},"VPC Subnet",{"type":35,"value":8812}," : A VPC Subnet is defined by a subrange of the network IP addresses assigned to the VPC.",{"type":26,"tag":54,"props":8814,"children":8815},{},[8816,8821],{"type":26,"tag":994,"props":8817,"children":8818},{},[8819],{"type":35,"value":8820},"Security Group",{"type":35,"value":8822}," : The VPC Security Groups are the way AWS implements firewalls between instances in the VPC.\nIn a VPC all inbound and outbound network traffic is denied by default. In order to allow traffic, a security group\nis defined and rules are assigned to the Security Group.",{"type":26,"tag":31,"props":8824,"children":8825},{},[8826],{"type":35,"value":8827},"The following is a terraform module to group all the needed networking resources in just one file.",{"type":26,"tag":121,"props":8829,"children":8833},{"className":8830,"code":8831,"language":8832,"meta":8,"style":8},"language-ruby shiki shiki-themes github-dark github-light","resource \"aws_vpc\" \"_\" {\n  cidr_block = var.vpc_cidr\n  enable_dns_support   = var.enable_dns_support\n  enable_dns_hostnames = var.enable_dns_hostnames\n  tags = {\n    Name = \"${var.app-name}-vpc\"\n  }\n}\n\nresource \"aws_internet_gateway\" \"gateway\" {\n  vpc_id = aws_vpc._.id\n  tags = {\n    Name = \"${var.app-name}-gateway\"\n  }\n}\n\nresource \"aws_route_table\" \"route_table\" {\n  vpc_id = aws_vpc._.id\n\n  dynamic \"route\" {\n    for_each = var.routes\n\n    content {\n      cidr_block     = route.value.cidr_block\n      gateway_id     = aws_internet_gateway.gateway.id\n      instance_id    = route.value.instance_id\n      nat_gateway_id = route.value.nat_gateway_id\n    }\n  }\n  tags = {\n    Name = \"${var.app-name}-route-table\"\n  }\n}\nresource \"aws_subnet\" \"subnet-a\" {\n  vpc_id                  = aws_vpc._.id\n  cidr_block              = \"10.0.32.0/20\"\n  availability_zone       = \"${var.region}a\"\n  map_public_ip_on_launch = true\n  tags = {\n    Name = \"${var.app-name}-subnet-a\"\n  }\n}\n \noutput \"_\" {\n  value = {\n    vpc_id = aws_vpc._.id\n    subnet_a = aws_subnet.subnet-a.id \n  }\n}\n","ruby",[8834],{"type":26,"tag":15,"props":8835,"children":8836},{"__ignoreMap":8},[8837,8845,8853,8861,8869,8877,8885,8893,8900,8907,8915,8923,8930,8938,8945,8952,8959,8967,8974,8981,8989,8997,9004,9012,9020,9028,9036,9044,9052,9060,9068,9077,9085,9093,9102,9111,9120,9129,9138,9146,9155,9163,9171,9180,9189,9198,9207,9216,9224],{"type":26,"tag":130,"props":8838,"children":8839},{"class":132,"line":133},[8840],{"type":26,"tag":130,"props":8841,"children":8842},{},[8843],{"type":35,"value":8844},"resource \"aws_vpc\" \"_\" {\n",{"type":26,"tag":130,"props":8846,"children":8847},{"class":132,"line":176},[8848],{"type":26,"tag":130,"props":8849,"children":8850},{},[8851],{"type":35,"value":8852},"  cidr_block = var.vpc_cidr\n",{"type":26,"tag":130,"props":8854,"children":8855},{"class":132,"line":205},[8856],{"type":26,"tag":130,"props":8857,"children":8858},{},[8859],{"type":35,"value":8860},"  enable_dns_support   = var.enable_dns_support\n",{"type":26,"tag":130,"props":8862,"children":8863},{"class":132,"line":231},[8864],{"type":26,"tag":130,"props":8865,"children":8866},{},[8867],{"type":35,"value":8868},"  enable_dns_hostnames = var.enable_dns_hostnames\n",{"type":26,"tag":130,"props":8870,"children":8871},{"class":132,"line":364},[8872],{"type":26,"tag":130,"props":8873,"children":8874},{},[8875],{"type":35,"value":8876},"  tags = {\n",{"type":26,"tag":130,"props":8878,"children":8879},{"class":132,"line":374},[8880],{"type":26,"tag":130,"props":8881,"children":8882},{},[8883],{"type":35,"value":8884},"    Name = \"${var.app-name}-vpc\"\n",{"type":26,"tag":130,"props":8886,"children":8887},{"class":132,"line":1353},[8888],{"type":26,"tag":130,"props":8889,"children":8890},{},[8891],{"type":35,"value":8892},"  }\n",{"type":26,"tag":130,"props":8894,"children":8895},{"class":132,"line":1361},[8896],{"type":26,"tag":130,"props":8897,"children":8898},{},[8899],{"type":35,"value":380},{"type":26,"tag":130,"props":8901,"children":8902},{"class":132,"line":1994},[8903],{"type":26,"tag":130,"props":8904,"children":8905},{"emptyLinePlaceholder":298},[8906],{"type":35,"value":301},{"type":26,"tag":130,"props":8908,"children":8909},{"class":132,"line":2007},[8910],{"type":26,"tag":130,"props":8911,"children":8912},{},[8913],{"type":35,"value":8914},"resource \"aws_internet_gateway\" \"gateway\" {\n",{"type":26,"tag":130,"props":8916,"children":8917},{"class":132,"line":2020},[8918],{"type":26,"tag":130,"props":8919,"children":8920},{},[8921],{"type":35,"value":8922},"  vpc_id = aws_vpc._.id\n",{"type":26,"tag":130,"props":8924,"children":8925},{"class":132,"line":2038},[8926],{"type":26,"tag":130,"props":8927,"children":8928},{},[8929],{"type":35,"value":8876},{"type":26,"tag":130,"props":8931,"children":8932},{"class":132,"line":2046},[8933],{"type":26,"tag":130,"props":8934,"children":8935},{},[8936],{"type":35,"value":8937},"    Name = \"${var.app-name}-gateway\"\n",{"type":26,"tag":130,"props":8939,"children":8940},{"class":132,"line":2059},[8941],{"type":26,"tag":130,"props":8942,"children":8943},{},[8944],{"type":35,"value":8892},{"type":26,"tag":130,"props":8946,"children":8947},{"class":132,"line":2082},[8948],{"type":26,"tag":130,"props":8949,"children":8950},{},[8951],{"type":35,"value":380},{"type":26,"tag":130,"props":8953,"children":8954},{"class":132,"line":2103},[8955],{"type":26,"tag":130,"props":8956,"children":8957},{"emptyLinePlaceholder":298},[8958],{"type":35,"value":301},{"type":26,"tag":130,"props":8960,"children":8961},{"class":132,"line":2121},[8962],{"type":26,"tag":130,"props":8963,"children":8964},{},[8965],{"type":35,"value":8966},"resource \"aws_route_table\" \"route_table\" {\n",{"type":26,"tag":130,"props":8968,"children":8969},{"class":132,"line":2134},[8970],{"type":26,"tag":130,"props":8971,"children":8972},{},[8973],{"type":35,"value":8922},{"type":26,"tag":130,"props":8975,"children":8976},{"class":132,"line":2152},[8977],{"type":26,"tag":130,"props":8978,"children":8979},{"emptyLinePlaceholder":298},[8980],{"type":35,"value":301},{"type":26,"tag":130,"props":8982,"children":8983},{"class":132,"line":2170},[8984],{"type":26,"tag":130,"props":8985,"children":8986},{},[8987],{"type":35,"value":8988},"  dynamic \"route\" {\n",{"type":26,"tag":130,"props":8990,"children":8991},{"class":132,"line":2178},[8992],{"type":26,"tag":130,"props":8993,"children":8994},{},[8995],{"type":35,"value":8996},"    for_each = var.routes\n",{"type":26,"tag":130,"props":8998,"children":8999},{"class":132,"line":2199},[9000],{"type":26,"tag":130,"props":9001,"children":9002},{"emptyLinePlaceholder":298},[9003],{"type":35,"value":301},{"type":26,"tag":130,"props":9005,"children":9006},{"class":132,"line":8552},[9007],{"type":26,"tag":130,"props":9008,"children":9009},{},[9010],{"type":35,"value":9011},"    content {\n",{"type":26,"tag":130,"props":9013,"children":9014},{"class":132,"line":8560},[9015],{"type":26,"tag":130,"props":9016,"children":9017},{},[9018],{"type":35,"value":9019},"      cidr_block     = route.value.cidr_block\n",{"type":26,"tag":130,"props":9021,"children":9022},{"class":132,"line":8568},[9023],{"type":26,"tag":130,"props":9024,"children":9025},{},[9026],{"type":35,"value":9027},"      gateway_id     = aws_internet_gateway.gateway.id\n",{"type":26,"tag":130,"props":9029,"children":9030},{"class":132,"line":8577},[9031],{"type":26,"tag":130,"props":9032,"children":9033},{},[9034],{"type":35,"value":9035},"      instance_id    = route.value.instance_id\n",{"type":26,"tag":130,"props":9037,"children":9038},{"class":132,"line":8586},[9039],{"type":26,"tag":130,"props":9040,"children":9041},{},[9042],{"type":35,"value":9043},"      nat_gateway_id = route.value.nat_gateway_id\n",{"type":26,"tag":130,"props":9045,"children":9047},{"class":132,"line":9046},28,[9048],{"type":26,"tag":130,"props":9049,"children":9050},{},[9051],{"type":35,"value":3962},{"type":26,"tag":130,"props":9053,"children":9055},{"class":132,"line":9054},29,[9056],{"type":26,"tag":130,"props":9057,"children":9058},{},[9059],{"type":35,"value":8892},{"type":26,"tag":130,"props":9061,"children":9063},{"class":132,"line":9062},30,[9064],{"type":26,"tag":130,"props":9065,"children":9066},{},[9067],{"type":35,"value":8876},{"type":26,"tag":130,"props":9069,"children":9071},{"class":132,"line":9070},31,[9072],{"type":26,"tag":130,"props":9073,"children":9074},{},[9075],{"type":35,"value":9076},"    Name = \"${var.app-name}-route-table\"\n",{"type":26,"tag":130,"props":9078,"children":9080},{"class":132,"line":9079},32,[9081],{"type":26,"tag":130,"props":9082,"children":9083},{},[9084],{"type":35,"value":8892},{"type":26,"tag":130,"props":9086,"children":9088},{"class":132,"line":9087},33,[9089],{"type":26,"tag":130,"props":9090,"children":9091},{},[9092],{"type":35,"value":380},{"type":26,"tag":130,"props":9094,"children":9096},{"class":132,"line":9095},34,[9097],{"type":26,"tag":130,"props":9098,"children":9099},{},[9100],{"type":35,"value":9101},"resource \"aws_subnet\" \"subnet-a\" {\n",{"type":26,"tag":130,"props":9103,"children":9105},{"class":132,"line":9104},35,[9106],{"type":26,"tag":130,"props":9107,"children":9108},{},[9109],{"type":35,"value":9110},"  vpc_id                  = aws_vpc._.id\n",{"type":26,"tag":130,"props":9112,"children":9114},{"class":132,"line":9113},36,[9115],{"type":26,"tag":130,"props":9116,"children":9117},{},[9118],{"type":35,"value":9119},"  cidr_block              = \"10.0.32.0/20\"\n",{"type":26,"tag":130,"props":9121,"children":9123},{"class":132,"line":9122},37,[9124],{"type":26,"tag":130,"props":9125,"children":9126},{},[9127],{"type":35,"value":9128},"  availability_zone       = \"${var.region}a\"\n",{"type":26,"tag":130,"props":9130,"children":9132},{"class":132,"line":9131},38,[9133],{"type":26,"tag":130,"props":9134,"children":9135},{},[9136],{"type":35,"value":9137},"  map_public_ip_on_launch = true\n",{"type":26,"tag":130,"props":9139,"children":9141},{"class":132,"line":9140},39,[9142],{"type":26,"tag":130,"props":9143,"children":9144},{},[9145],{"type":35,"value":8876},{"type":26,"tag":130,"props":9147,"children":9149},{"class":132,"line":9148},40,[9150],{"type":26,"tag":130,"props":9151,"children":9152},{},[9153],{"type":35,"value":9154},"    Name = \"${var.app-name}-subnet-a\"\n",{"type":26,"tag":130,"props":9156,"children":9158},{"class":132,"line":9157},41,[9159],{"type":26,"tag":130,"props":9160,"children":9161},{},[9162],{"type":35,"value":8892},{"type":26,"tag":130,"props":9164,"children":9166},{"class":132,"line":9165},42,[9167],{"type":26,"tag":130,"props":9168,"children":9169},{},[9170],{"type":35,"value":380},{"type":26,"tag":130,"props":9172,"children":9174},{"class":132,"line":9173},43,[9175],{"type":26,"tag":130,"props":9176,"children":9177},{},[9178],{"type":35,"value":9179}," \n",{"type":26,"tag":130,"props":9181,"children":9183},{"class":132,"line":9182},44,[9184],{"type":26,"tag":130,"props":9185,"children":9186},{},[9187],{"type":35,"value":9188},"output \"_\" {\n",{"type":26,"tag":130,"props":9190,"children":9192},{"class":132,"line":9191},45,[9193],{"type":26,"tag":130,"props":9194,"children":9195},{},[9196],{"type":35,"value":9197},"  value = {\n",{"type":26,"tag":130,"props":9199,"children":9201},{"class":132,"line":9200},46,[9202],{"type":26,"tag":130,"props":9203,"children":9204},{},[9205],{"type":35,"value":9206},"    vpc_id = aws_vpc._.id\n",{"type":26,"tag":130,"props":9208,"children":9210},{"class":132,"line":9209},47,[9211],{"type":26,"tag":130,"props":9212,"children":9213},{},[9214],{"type":35,"value":9215},"    subnet_a = aws_subnet.subnet-a.id \n",{"type":26,"tag":130,"props":9217,"children":9219},{"class":132,"line":9218},48,[9220],{"type":26,"tag":130,"props":9221,"children":9222},{},[9223],{"type":35,"value":8892},{"type":26,"tag":130,"props":9225,"children":9227},{"class":132,"line":9226},49,[9228],{"type":26,"tag":130,"props":9229,"children":9230},{},[9231],{"type":35,"value":380},{"type":26,"tag":38,"props":9233,"children":9235},{"id":9234},"step-2-rds-mysql-database",[9236],{"type":35,"value":9237},"Step 2 - RDS MySql database",{"type":26,"tag":31,"props":9239,"children":9240},{},[9241],{"type":35,"value":9242},"Now we need to define the RDS Database with the corresponding security group, note that RDS security group has a reference\nto another security group, this will allow ingress traffic from elastic beanstalk instance to the database.",{"type":26,"tag":121,"props":9244,"children":9246},{"className":8830,"code":9245,"language":8832,"meta":8,"style":8},"resource \"aws_security_group\" \"rds-sg\" {\n\n  name = \"rds-sg\"\n  description = \"RDS (terraform-managed)\"\n  vpc_id = module.vpc._.vpc_id\n\n  # Only MySQL port in for elastic beanstalk instance\n  ingress {\n    from_port       = var.rds-port\n    to_port         = var.rds-port\n    protocol        = \"tcp\"\n    security_groups = [aws_security_group.eb-sg.id]\n  }\n  # Allow all outbound traffic.\n  egress {\n    from_port   = 0\n    to_port     = 0\n    protocol    = \"-1\"\n    cidr_blocks = [\"0.0.0.0/0\"]\n  }\n  tags = {\n    Name = \"RDS_sg\"\n  }\n}\n\nresource \"aws_db_instance\" \"rds-db\" {\n\n  name                    = var.rds-schema\n  identifier              = var.rds-identifier\n\n  allocated_storage       = 20\n  backup_retention_period = 7\n  backup_window           = \"10:46-11:16\"\n  maintenance_window      = \"Mon:00:00-Mon:03:00\"\n  engine                  = \"mysql\"\n  engine_version          = \"8.0.15\"\n  instance_class          = \"db.t2.micro\"\n  username                = var.rds-username\n  password                = var.rds-password\n  port                    = var.rds-port\n  publicly_accessible     = true\n  storage_type            = \"gp2\"\n\n  allow_major_version_upgrade  = false\n  auto_minor_version_upgrade   = true\n  performance_insights_enabled = false\n  skip_final_snapshot          = true\n  final_snapshot_identifier = \"database-${var.rds-schema}-snapshot\"\n\n  vpc_security_group_ids = [aws_security_group.rds-sg.id]\n  availability_zone         = var.rds-availability_zone\n  multi_az                  = var.rds-multi_az \n}\n",[9247],{"type":26,"tag":15,"props":9248,"children":9249},{"__ignoreMap":8},[9250,9258,9265,9273,9281,9289,9296,9304,9312,9320,9328,9336,9344,9351,9359,9367,9375,9383,9391,9399,9406,9413,9421,9428,9435,9442,9450,9457,9465,9473,9480,9488,9496,9504,9512,9520,9528,9536,9544,9552,9560,9568,9576,9583,9591,9599,9607,9615,9623,9630,9639,9648,9657],{"type":26,"tag":130,"props":9251,"children":9252},{"class":132,"line":133},[9253],{"type":26,"tag":130,"props":9254,"children":9255},{},[9256],{"type":35,"value":9257},"resource \"aws_security_group\" \"rds-sg\" {\n",{"type":26,"tag":130,"props":9259,"children":9260},{"class":132,"line":176},[9261],{"type":26,"tag":130,"props":9262,"children":9263},{"emptyLinePlaceholder":298},[9264],{"type":35,"value":301},{"type":26,"tag":130,"props":9266,"children":9267},{"class":132,"line":205},[9268],{"type":26,"tag":130,"props":9269,"children":9270},{},[9271],{"type":35,"value":9272},"  name = \"rds-sg\"\n",{"type":26,"tag":130,"props":9274,"children":9275},{"class":132,"line":231},[9276],{"type":26,"tag":130,"props":9277,"children":9278},{},[9279],{"type":35,"value":9280},"  description = \"RDS (terraform-managed)\"\n",{"type":26,"tag":130,"props":9282,"children":9283},{"class":132,"line":364},[9284],{"type":26,"tag":130,"props":9285,"children":9286},{},[9287],{"type":35,"value":9288},"  vpc_id = module.vpc._.vpc_id\n",{"type":26,"tag":130,"props":9290,"children":9291},{"class":132,"line":374},[9292],{"type":26,"tag":130,"props":9293,"children":9294},{"emptyLinePlaceholder":298},[9295],{"type":35,"value":301},{"type":26,"tag":130,"props":9297,"children":9298},{"class":132,"line":1353},[9299],{"type":26,"tag":130,"props":9300,"children":9301},{},[9302],{"type":35,"value":9303},"  # Only MySQL port in for elastic beanstalk instance\n",{"type":26,"tag":130,"props":9305,"children":9306},{"class":132,"line":1361},[9307],{"type":26,"tag":130,"props":9308,"children":9309},{},[9310],{"type":35,"value":9311},"  ingress {\n",{"type":26,"tag":130,"props":9313,"children":9314},{"class":132,"line":1994},[9315],{"type":26,"tag":130,"props":9316,"children":9317},{},[9318],{"type":35,"value":9319},"    from_port       = var.rds-port\n",{"type":26,"tag":130,"props":9321,"children":9322},{"class":132,"line":2007},[9323],{"type":26,"tag":130,"props":9324,"children":9325},{},[9326],{"type":35,"value":9327},"    to_port         = var.rds-port\n",{"type":26,"tag":130,"props":9329,"children":9330},{"class":132,"line":2020},[9331],{"type":26,"tag":130,"props":9332,"children":9333},{},[9334],{"type":35,"value":9335},"    protocol        = \"tcp\"\n",{"type":26,"tag":130,"props":9337,"children":9338},{"class":132,"line":2038},[9339],{"type":26,"tag":130,"props":9340,"children":9341},{},[9342],{"type":35,"value":9343},"    security_groups = [aws_security_group.eb-sg.id]\n",{"type":26,"tag":130,"props":9345,"children":9346},{"class":132,"line":2046},[9347],{"type":26,"tag":130,"props":9348,"children":9349},{},[9350],{"type":35,"value":8892},{"type":26,"tag":130,"props":9352,"children":9353},{"class":132,"line":2059},[9354],{"type":26,"tag":130,"props":9355,"children":9356},{},[9357],{"type":35,"value":9358},"  # Allow all outbound traffic.\n",{"type":26,"tag":130,"props":9360,"children":9361},{"class":132,"line":2082},[9362],{"type":26,"tag":130,"props":9363,"children":9364},{},[9365],{"type":35,"value":9366},"  egress {\n",{"type":26,"tag":130,"props":9368,"children":9369},{"class":132,"line":2103},[9370],{"type":26,"tag":130,"props":9371,"children":9372},{},[9373],{"type":35,"value":9374},"    from_port   = 0\n",{"type":26,"tag":130,"props":9376,"children":9377},{"class":132,"line":2121},[9378],{"type":26,"tag":130,"props":9379,"children":9380},{},[9381],{"type":35,"value":9382},"    to_port     = 0\n",{"type":26,"tag":130,"props":9384,"children":9385},{"class":132,"line":2134},[9386],{"type":26,"tag":130,"props":9387,"children":9388},{},[9389],{"type":35,"value":9390},"    protocol    = \"-1\"\n",{"type":26,"tag":130,"props":9392,"children":9393},{"class":132,"line":2152},[9394],{"type":26,"tag":130,"props":9395,"children":9396},{},[9397],{"type":35,"value":9398},"    cidr_blocks = [\"0.0.0.0/0\"]\n",{"type":26,"tag":130,"props":9400,"children":9401},{"class":132,"line":2170},[9402],{"type":26,"tag":130,"props":9403,"children":9404},{},[9405],{"type":35,"value":8892},{"type":26,"tag":130,"props":9407,"children":9408},{"class":132,"line":2178},[9409],{"type":26,"tag":130,"props":9410,"children":9411},{},[9412],{"type":35,"value":8876},{"type":26,"tag":130,"props":9414,"children":9415},{"class":132,"line":2199},[9416],{"type":26,"tag":130,"props":9417,"children":9418},{},[9419],{"type":35,"value":9420},"    Name = \"RDS_sg\"\n",{"type":26,"tag":130,"props":9422,"children":9423},{"class":132,"line":8552},[9424],{"type":26,"tag":130,"props":9425,"children":9426},{},[9427],{"type":35,"value":8892},{"type":26,"tag":130,"props":9429,"children":9430},{"class":132,"line":8560},[9431],{"type":26,"tag":130,"props":9432,"children":9433},{},[9434],{"type":35,"value":380},{"type":26,"tag":130,"props":9436,"children":9437},{"class":132,"line":8568},[9438],{"type":26,"tag":130,"props":9439,"children":9440},{"emptyLinePlaceholder":298},[9441],{"type":35,"value":301},{"type":26,"tag":130,"props":9443,"children":9444},{"class":132,"line":8577},[9445],{"type":26,"tag":130,"props":9446,"children":9447},{},[9448],{"type":35,"value":9449},"resource \"aws_db_instance\" \"rds-db\" {\n",{"type":26,"tag":130,"props":9451,"children":9452},{"class":132,"line":8586},[9453],{"type":26,"tag":130,"props":9454,"children":9455},{"emptyLinePlaceholder":298},[9456],{"type":35,"value":301},{"type":26,"tag":130,"props":9458,"children":9459},{"class":132,"line":9046},[9460],{"type":26,"tag":130,"props":9461,"children":9462},{},[9463],{"type":35,"value":9464},"  name                    = var.rds-schema\n",{"type":26,"tag":130,"props":9466,"children":9467},{"class":132,"line":9054},[9468],{"type":26,"tag":130,"props":9469,"children":9470},{},[9471],{"type":35,"value":9472},"  identifier              = var.rds-identifier\n",{"type":26,"tag":130,"props":9474,"children":9475},{"class":132,"line":9062},[9476],{"type":26,"tag":130,"props":9477,"children":9478},{"emptyLinePlaceholder":298},[9479],{"type":35,"value":301},{"type":26,"tag":130,"props":9481,"children":9482},{"class":132,"line":9070},[9483],{"type":26,"tag":130,"props":9484,"children":9485},{},[9486],{"type":35,"value":9487},"  allocated_storage       = 20\n",{"type":26,"tag":130,"props":9489,"children":9490},{"class":132,"line":9079},[9491],{"type":26,"tag":130,"props":9492,"children":9493},{},[9494],{"type":35,"value":9495},"  backup_retention_period = 7\n",{"type":26,"tag":130,"props":9497,"children":9498},{"class":132,"line":9087},[9499],{"type":26,"tag":130,"props":9500,"children":9501},{},[9502],{"type":35,"value":9503},"  backup_window           = \"10:46-11:16\"\n",{"type":26,"tag":130,"props":9505,"children":9506},{"class":132,"line":9095},[9507],{"type":26,"tag":130,"props":9508,"children":9509},{},[9510],{"type":35,"value":9511},"  maintenance_window      = \"Mon:00:00-Mon:03:00\"\n",{"type":26,"tag":130,"props":9513,"children":9514},{"class":132,"line":9104},[9515],{"type":26,"tag":130,"props":9516,"children":9517},{},[9518],{"type":35,"value":9519},"  engine                  = \"mysql\"\n",{"type":26,"tag":130,"props":9521,"children":9522},{"class":132,"line":9113},[9523],{"type":26,"tag":130,"props":9524,"children":9525},{},[9526],{"type":35,"value":9527},"  engine_version          = \"8.0.15\"\n",{"type":26,"tag":130,"props":9529,"children":9530},{"class":132,"line":9122},[9531],{"type":26,"tag":130,"props":9532,"children":9533},{},[9534],{"type":35,"value":9535},"  instance_class          = \"db.t2.micro\"\n",{"type":26,"tag":130,"props":9537,"children":9538},{"class":132,"line":9131},[9539],{"type":26,"tag":130,"props":9540,"children":9541},{},[9542],{"type":35,"value":9543},"  username                = var.rds-username\n",{"type":26,"tag":130,"props":9545,"children":9546},{"class":132,"line":9140},[9547],{"type":26,"tag":130,"props":9548,"children":9549},{},[9550],{"type":35,"value":9551},"  password                = var.rds-password\n",{"type":26,"tag":130,"props":9553,"children":9554},{"class":132,"line":9148},[9555],{"type":26,"tag":130,"props":9556,"children":9557},{},[9558],{"type":35,"value":9559},"  port                    = var.rds-port\n",{"type":26,"tag":130,"props":9561,"children":9562},{"class":132,"line":9157},[9563],{"type":26,"tag":130,"props":9564,"children":9565},{},[9566],{"type":35,"value":9567},"  publicly_accessible     = true\n",{"type":26,"tag":130,"props":9569,"children":9570},{"class":132,"line":9165},[9571],{"type":26,"tag":130,"props":9572,"children":9573},{},[9574],{"type":35,"value":9575},"  storage_type            = \"gp2\"\n",{"type":26,"tag":130,"props":9577,"children":9578},{"class":132,"line":9173},[9579],{"type":26,"tag":130,"props":9580,"children":9581},{"emptyLinePlaceholder":298},[9582],{"type":35,"value":301},{"type":26,"tag":130,"props":9584,"children":9585},{"class":132,"line":9182},[9586],{"type":26,"tag":130,"props":9587,"children":9588},{},[9589],{"type":35,"value":9590},"  allow_major_version_upgrade  = false\n",{"type":26,"tag":130,"props":9592,"children":9593},{"class":132,"line":9191},[9594],{"type":26,"tag":130,"props":9595,"children":9596},{},[9597],{"type":35,"value":9598},"  auto_minor_version_upgrade   = true\n",{"type":26,"tag":130,"props":9600,"children":9601},{"class":132,"line":9200},[9602],{"type":26,"tag":130,"props":9603,"children":9604},{},[9605],{"type":35,"value":9606},"  performance_insights_enabled = false\n",{"type":26,"tag":130,"props":9608,"children":9609},{"class":132,"line":9209},[9610],{"type":26,"tag":130,"props":9611,"children":9612},{},[9613],{"type":35,"value":9614},"  skip_final_snapshot          = true\n",{"type":26,"tag":130,"props":9616,"children":9617},{"class":132,"line":9218},[9618],{"type":26,"tag":130,"props":9619,"children":9620},{},[9621],{"type":35,"value":9622},"  final_snapshot_identifier = \"database-${var.rds-schema}-snapshot\"\n",{"type":26,"tag":130,"props":9624,"children":9625},{"class":132,"line":9226},[9626],{"type":26,"tag":130,"props":9627,"children":9628},{"emptyLinePlaceholder":298},[9629],{"type":35,"value":301},{"type":26,"tag":130,"props":9631,"children":9633},{"class":132,"line":9632},50,[9634],{"type":26,"tag":130,"props":9635,"children":9636},{},[9637],{"type":35,"value":9638},"  vpc_security_group_ids = [aws_security_group.rds-sg.id]\n",{"type":26,"tag":130,"props":9640,"children":9642},{"class":132,"line":9641},51,[9643],{"type":26,"tag":130,"props":9644,"children":9645},{},[9646],{"type":35,"value":9647},"  availability_zone         = var.rds-availability_zone\n",{"type":26,"tag":130,"props":9649,"children":9651},{"class":132,"line":9650},52,[9652],{"type":26,"tag":130,"props":9653,"children":9654},{},[9655],{"type":35,"value":9656},"  multi_az                  = var.rds-multi_az \n",{"type":26,"tag":130,"props":9658,"children":9660},{"class":132,"line":9659},53,[9661],{"type":26,"tag":130,"props":9662,"children":9663},{},[9664],{"type":35,"value":380},{"type":26,"tag":38,"props":9666,"children":9668},{"id":9667},"step-3-elastic-beanstalk",[9669],{"type":35,"value":9670},"Step 3 - Elastic Beanstalk",{"type":26,"tag":31,"props":9672,"children":9673},{},[9674,9676,9681],{"type":35,"value":9675},"Elastic Beanstalk is a great way to deploy Java applications, you only need to focus on the application. The service\ncan be configured as a ",{"type":26,"tag":994,"props":9677,"children":9678},{},[9679],{"type":35,"value":9680},"single instance or load balanced",{"type":35,"value":9682},". In this example we are going to deploy single instance, but\nfor production applications is highly recommended configuring as load balanced with a minimum of 2 instances, is not\nonly about performance, with this configuration when you deploy a new version AWS will replace 1 instance at the time\nand wait to be in healthy state, this way we can achieve 0 downtime.",{"type":26,"tag":121,"props":9684,"children":9686},{"className":8830,"code":9685,"language":8832,"meta":8,"style":8},"resource \"aws_security_group\" \"eb-sg\" {\n  name = \"eb-sg\"\n  description = \"SecurityGroup for ElasticBeanstalk environment.\"\n  vpc_id = module.vpc._.vpc_id\n  ingress {\n    from_port = 80\n    to_port = 80\n    protocol = \"tcp\"\n    cidr_blocks = [\"0.0.0.0/0\"]\n    ipv6_cidr_blocks = [\"::/0\"]\n  }\n  ingress {\n    from_port = 587\n    to_port = 587\n    protocol = \"tcp\"\n    cidr_blocks = [\"0.0.0.0/0\"]\n    ipv6_cidr_blocks = [\"::/0\"]\n  }\n  egress {\n    from_port = 0\n    to_port = 0\n    protocol = \"-1\"\n    cidr_blocks = [\"0.0.0.0/0\"]\n  }\n  tags = {\n    Name = \"EB_sg\"\n  }\n}\n\n# ElasticBeanstalk - Application\nresource \"aws_elastic_beanstalk_application\" \"eb-application\" {\n  name = var.app-name\n  depends_on = [aws_db_instance.rds-db]\n}\n\n# ElasticBeanstalk - Environment\nresource \"aws_elastic_beanstalk_environment\" \"eb-env-prod\" {\n\n  depends_on = [aws_db_instance.rds-db]\n\n  name                = \"${var.app-name}-prod\"\n  application         = aws_elastic_beanstalk_application.eb-application.name\n  solution_stack_name = data.aws_elastic_beanstalk_solution_stack.java8.name\n  cname_prefix        = var.app-name\n\n  setting {\n    namespace = \"aws:autoscaling:launchconfiguration\"\n    name = \"InstanceType\"\n    value = \"t2.micro\"\n  }\n  setting {\n    namespace = \"aws:elasticbeanstalk:environment\"\n    name = \"EnvironmentType\"\n    value = \"SingleInstance\"\n  }\n  setting {\n    namespace = \"aws:autoscaling:launchconfiguration\"\n    name = \"IamInstanceProfile\"\n    value = \"aws-elasticbeanstalk-ec2-role\"\n  }\n  setting {\n    namespace = \"aws:autoscaling:launchconfiguration\"\n    name = \"InstanceType\"\n    value = \"t2.micro\"\n  }\n  setting {\n    namespace = \"aws:elasticbeanstalk:application:environment\"\n    name = \"SPRING_PROFILES_ACTIVE\"\n    value = \"prod\"\n  }\n  setting {\n    namespace = \"aws:elasticbeanstalk:application:environment\"\n    name = \"SPRING_DATASOURCE_URL\"\n    value = \"jdbc:mysql://${aws_db_instance.rds-db.endpoint}/${aws_db_instance.rds-db.name}?useSSL=false\"\n  }\n  setting {\n    namespace = \"aws:elasticbeanstalk:application:environment\"\n    name = \"SPRING_DATASOURCE_USERNAME\"\n    value = aws_db_instance.rds-db.username\n  }\n  setting {\n    namespace = \"aws:elasticbeanstalk:application:environment\"\n    name = \"SPRING_DATASOURCE_PASSWORD\"\n    value = aws_db_instance.rds-db.password\n  }\n  setting {\n    namespace = \"aws:autoscaling:launchconfiguration\"\n    name = \"SecurityGroups\"\n    value = aws_security_group.eb-sg.id\n  }\n  setting {\n    namespace = \"aws:ec2:vpc\"\n    name      = \"VPCId\"\n    value     = module.vpc._.vpc_id\n  }\n  setting {\n    namespace = \"aws:ec2:vpc\"\n    name      = \"Subnets\"\n    value     = module.vpc._.subnet_a\n  }\n  setting {\n    namespace = \"aws:ec2:vpc\"\n    name = \"VPCId\"\n    value = module.vpc._.vpc_id\n  }\n  setting {\n    namespace = \"aws:ec2:vpc\"\n    name = \"AssociatePublicIpAddress\"\n    value = \"true\"\n  }\n}\n",[9687],{"type":26,"tag":15,"props":9688,"children":9689},{"__ignoreMap":8},[9690,9698,9706,9714,9721,9728,9736,9744,9752,9759,9767,9774,9781,9789,9797,9804,9811,9818,9825,9832,9840,9848,9856,9863,9870,9877,9885,9892,9899,9906,9914,9922,9930,9938,9945,9952,9960,9968,9975,9982,9989,9997,10005,10013,10021,10028,10036,10044,10052,10060,10067,10074,10082,10090,10099,10107,10115,10123,10132,10141,10149,10157,10165,10173,10181,10189,10197,10206,10215,10224,10232,10240,10248,10257,10266,10274,10282,10290,10299,10308,10316,10324,10332,10341,10350,10358,10366,10374,10383,10392,10400,10408,10417,10426,10435,10443,10451,10459,10468,10477,10485,10493,10501,10510,10519,10527,10535,10543,10552,10561,10569],{"type":26,"tag":130,"props":9691,"children":9692},{"class":132,"line":133},[9693],{"type":26,"tag":130,"props":9694,"children":9695},{},[9696],{"type":35,"value":9697},"resource \"aws_security_group\" \"eb-sg\" {\n",{"type":26,"tag":130,"props":9699,"children":9700},{"class":132,"line":176},[9701],{"type":26,"tag":130,"props":9702,"children":9703},{},[9704],{"type":35,"value":9705},"  name = \"eb-sg\"\n",{"type":26,"tag":130,"props":9707,"children":9708},{"class":132,"line":205},[9709],{"type":26,"tag":130,"props":9710,"children":9711},{},[9712],{"type":35,"value":9713},"  description = \"SecurityGroup for ElasticBeanstalk environment.\"\n",{"type":26,"tag":130,"props":9715,"children":9716},{"class":132,"line":231},[9717],{"type":26,"tag":130,"props":9718,"children":9719},{},[9720],{"type":35,"value":9288},{"type":26,"tag":130,"props":9722,"children":9723},{"class":132,"line":364},[9724],{"type":26,"tag":130,"props":9725,"children":9726},{},[9727],{"type":35,"value":9311},{"type":26,"tag":130,"props":9729,"children":9730},{"class":132,"line":374},[9731],{"type":26,"tag":130,"props":9732,"children":9733},{},[9734],{"type":35,"value":9735},"    from_port = 80\n",{"type":26,"tag":130,"props":9737,"children":9738},{"class":132,"line":1353},[9739],{"type":26,"tag":130,"props":9740,"children":9741},{},[9742],{"type":35,"value":9743},"    to_port = 80\n",{"type":26,"tag":130,"props":9745,"children":9746},{"class":132,"line":1361},[9747],{"type":26,"tag":130,"props":9748,"children":9749},{},[9750],{"type":35,"value":9751},"    protocol = \"tcp\"\n",{"type":26,"tag":130,"props":9753,"children":9754},{"class":132,"line":1994},[9755],{"type":26,"tag":130,"props":9756,"children":9757},{},[9758],{"type":35,"value":9398},{"type":26,"tag":130,"props":9760,"children":9761},{"class":132,"line":2007},[9762],{"type":26,"tag":130,"props":9763,"children":9764},{},[9765],{"type":35,"value":9766},"    ipv6_cidr_blocks = [\"::/0\"]\n",{"type":26,"tag":130,"props":9768,"children":9769},{"class":132,"line":2020},[9770],{"type":26,"tag":130,"props":9771,"children":9772},{},[9773],{"type":35,"value":8892},{"type":26,"tag":130,"props":9775,"children":9776},{"class":132,"line":2038},[9777],{"type":26,"tag":130,"props":9778,"children":9779},{},[9780],{"type":35,"value":9311},{"type":26,"tag":130,"props":9782,"children":9783},{"class":132,"line":2046},[9784],{"type":26,"tag":130,"props":9785,"children":9786},{},[9787],{"type":35,"value":9788},"    from_port = 587\n",{"type":26,"tag":130,"props":9790,"children":9791},{"class":132,"line":2059},[9792],{"type":26,"tag":130,"props":9793,"children":9794},{},[9795],{"type":35,"value":9796},"    to_port = 587\n",{"type":26,"tag":130,"props":9798,"children":9799},{"class":132,"line":2082},[9800],{"type":26,"tag":130,"props":9801,"children":9802},{},[9803],{"type":35,"value":9751},{"type":26,"tag":130,"props":9805,"children":9806},{"class":132,"line":2103},[9807],{"type":26,"tag":130,"props":9808,"children":9809},{},[9810],{"type":35,"value":9398},{"type":26,"tag":130,"props":9812,"children":9813},{"class":132,"line":2121},[9814],{"type":26,"tag":130,"props":9815,"children":9816},{},[9817],{"type":35,"value":9766},{"type":26,"tag":130,"props":9819,"children":9820},{"class":132,"line":2134},[9821],{"type":26,"tag":130,"props":9822,"children":9823},{},[9824],{"type":35,"value":8892},{"type":26,"tag":130,"props":9826,"children":9827},{"class":132,"line":2152},[9828],{"type":26,"tag":130,"props":9829,"children":9830},{},[9831],{"type":35,"value":9366},{"type":26,"tag":130,"props":9833,"children":9834},{"class":132,"line":2170},[9835],{"type":26,"tag":130,"props":9836,"children":9837},{},[9838],{"type":35,"value":9839},"    from_port = 0\n",{"type":26,"tag":130,"props":9841,"children":9842},{"class":132,"line":2178},[9843],{"type":26,"tag":130,"props":9844,"children":9845},{},[9846],{"type":35,"value":9847},"    to_port = 0\n",{"type":26,"tag":130,"props":9849,"children":9850},{"class":132,"line":2199},[9851],{"type":26,"tag":130,"props":9852,"children":9853},{},[9854],{"type":35,"value":9855},"    protocol = \"-1\"\n",{"type":26,"tag":130,"props":9857,"children":9858},{"class":132,"line":8552},[9859],{"type":26,"tag":130,"props":9860,"children":9861},{},[9862],{"type":35,"value":9398},{"type":26,"tag":130,"props":9864,"children":9865},{"class":132,"line":8560},[9866],{"type":26,"tag":130,"props":9867,"children":9868},{},[9869],{"type":35,"value":8892},{"type":26,"tag":130,"props":9871,"children":9872},{"class":132,"line":8568},[9873],{"type":26,"tag":130,"props":9874,"children":9875},{},[9876],{"type":35,"value":8876},{"type":26,"tag":130,"props":9878,"children":9879},{"class":132,"line":8577},[9880],{"type":26,"tag":130,"props":9881,"children":9882},{},[9883],{"type":35,"value":9884},"    Name = \"EB_sg\"\n",{"type":26,"tag":130,"props":9886,"children":9887},{"class":132,"line":8586},[9888],{"type":26,"tag":130,"props":9889,"children":9890},{},[9891],{"type":35,"value":8892},{"type":26,"tag":130,"props":9893,"children":9894},{"class":132,"line":9046},[9895],{"type":26,"tag":130,"props":9896,"children":9897},{},[9898],{"type":35,"value":380},{"type":26,"tag":130,"props":9900,"children":9901},{"class":132,"line":9054},[9902],{"type":26,"tag":130,"props":9903,"children":9904},{"emptyLinePlaceholder":298},[9905],{"type":35,"value":301},{"type":26,"tag":130,"props":9907,"children":9908},{"class":132,"line":9062},[9909],{"type":26,"tag":130,"props":9910,"children":9911},{},[9912],{"type":35,"value":9913},"# ElasticBeanstalk - Application\n",{"type":26,"tag":130,"props":9915,"children":9916},{"class":132,"line":9070},[9917],{"type":26,"tag":130,"props":9918,"children":9919},{},[9920],{"type":35,"value":9921},"resource \"aws_elastic_beanstalk_application\" \"eb-application\" {\n",{"type":26,"tag":130,"props":9923,"children":9924},{"class":132,"line":9079},[9925],{"type":26,"tag":130,"props":9926,"children":9927},{},[9928],{"type":35,"value":9929},"  name = var.app-name\n",{"type":26,"tag":130,"props":9931,"children":9932},{"class":132,"line":9087},[9933],{"type":26,"tag":130,"props":9934,"children":9935},{},[9936],{"type":35,"value":9937},"  depends_on = [aws_db_instance.rds-db]\n",{"type":26,"tag":130,"props":9939,"children":9940},{"class":132,"line":9095},[9941],{"type":26,"tag":130,"props":9942,"children":9943},{},[9944],{"type":35,"value":380},{"type":26,"tag":130,"props":9946,"children":9947},{"class":132,"line":9104},[9948],{"type":26,"tag":130,"props":9949,"children":9950},{"emptyLinePlaceholder":298},[9951],{"type":35,"value":301},{"type":26,"tag":130,"props":9953,"children":9954},{"class":132,"line":9113},[9955],{"type":26,"tag":130,"props":9956,"children":9957},{},[9958],{"type":35,"value":9959},"# ElasticBeanstalk - Environment\n",{"type":26,"tag":130,"props":9961,"children":9962},{"class":132,"line":9122},[9963],{"type":26,"tag":130,"props":9964,"children":9965},{},[9966],{"type":35,"value":9967},"resource \"aws_elastic_beanstalk_environment\" \"eb-env-prod\" {\n",{"type":26,"tag":130,"props":9969,"children":9970},{"class":132,"line":9131},[9971],{"type":26,"tag":130,"props":9972,"children":9973},{"emptyLinePlaceholder":298},[9974],{"type":35,"value":301},{"type":26,"tag":130,"props":9976,"children":9977},{"class":132,"line":9140},[9978],{"type":26,"tag":130,"props":9979,"children":9980},{},[9981],{"type":35,"value":9937},{"type":26,"tag":130,"props":9983,"children":9984},{"class":132,"line":9148},[9985],{"type":26,"tag":130,"props":9986,"children":9987},{"emptyLinePlaceholder":298},[9988],{"type":35,"value":301},{"type":26,"tag":130,"props":9990,"children":9991},{"class":132,"line":9157},[9992],{"type":26,"tag":130,"props":9993,"children":9994},{},[9995],{"type":35,"value":9996},"  name                = \"${var.app-name}-prod\"\n",{"type":26,"tag":130,"props":9998,"children":9999},{"class":132,"line":9165},[10000],{"type":26,"tag":130,"props":10001,"children":10002},{},[10003],{"type":35,"value":10004},"  application         = aws_elastic_beanstalk_application.eb-application.name\n",{"type":26,"tag":130,"props":10006,"children":10007},{"class":132,"line":9173},[10008],{"type":26,"tag":130,"props":10009,"children":10010},{},[10011],{"type":35,"value":10012},"  solution_stack_name = data.aws_elastic_beanstalk_solution_stack.java8.name\n",{"type":26,"tag":130,"props":10014,"children":10015},{"class":132,"line":9182},[10016],{"type":26,"tag":130,"props":10017,"children":10018},{},[10019],{"type":35,"value":10020},"  cname_prefix        = var.app-name\n",{"type":26,"tag":130,"props":10022,"children":10023},{"class":132,"line":9191},[10024],{"type":26,"tag":130,"props":10025,"children":10026},{"emptyLinePlaceholder":298},[10027],{"type":35,"value":301},{"type":26,"tag":130,"props":10029,"children":10030},{"class":132,"line":9200},[10031],{"type":26,"tag":130,"props":10032,"children":10033},{},[10034],{"type":35,"value":10035},"  setting {\n",{"type":26,"tag":130,"props":10037,"children":10038},{"class":132,"line":9209},[10039],{"type":26,"tag":130,"props":10040,"children":10041},{},[10042],{"type":35,"value":10043},"    namespace = \"aws:autoscaling:launchconfiguration\"\n",{"type":26,"tag":130,"props":10045,"children":10046},{"class":132,"line":9218},[10047],{"type":26,"tag":130,"props":10048,"children":10049},{},[10050],{"type":35,"value":10051},"    name = \"InstanceType\"\n",{"type":26,"tag":130,"props":10053,"children":10054},{"class":132,"line":9226},[10055],{"type":26,"tag":130,"props":10056,"children":10057},{},[10058],{"type":35,"value":10059},"    value = \"t2.micro\"\n",{"type":26,"tag":130,"props":10061,"children":10062},{"class":132,"line":9632},[10063],{"type":26,"tag":130,"props":10064,"children":10065},{},[10066],{"type":35,"value":8892},{"type":26,"tag":130,"props":10068,"children":10069},{"class":132,"line":9641},[10070],{"type":26,"tag":130,"props":10071,"children":10072},{},[10073],{"type":35,"value":10035},{"type":26,"tag":130,"props":10075,"children":10076},{"class":132,"line":9650},[10077],{"type":26,"tag":130,"props":10078,"children":10079},{},[10080],{"type":35,"value":10081},"    namespace = \"aws:elasticbeanstalk:environment\"\n",{"type":26,"tag":130,"props":10083,"children":10084},{"class":132,"line":9659},[10085],{"type":26,"tag":130,"props":10086,"children":10087},{},[10088],{"type":35,"value":10089},"    name = \"EnvironmentType\"\n",{"type":26,"tag":130,"props":10091,"children":10093},{"class":132,"line":10092},54,[10094],{"type":26,"tag":130,"props":10095,"children":10096},{},[10097],{"type":35,"value":10098},"    value = \"SingleInstance\"\n",{"type":26,"tag":130,"props":10100,"children":10102},{"class":132,"line":10101},55,[10103],{"type":26,"tag":130,"props":10104,"children":10105},{},[10106],{"type":35,"value":8892},{"type":26,"tag":130,"props":10108,"children":10110},{"class":132,"line":10109},56,[10111],{"type":26,"tag":130,"props":10112,"children":10113},{},[10114],{"type":35,"value":10035},{"type":26,"tag":130,"props":10116,"children":10118},{"class":132,"line":10117},57,[10119],{"type":26,"tag":130,"props":10120,"children":10121},{},[10122],{"type":35,"value":10043},{"type":26,"tag":130,"props":10124,"children":10126},{"class":132,"line":10125},58,[10127],{"type":26,"tag":130,"props":10128,"children":10129},{},[10130],{"type":35,"value":10131},"    name = \"IamInstanceProfile\"\n",{"type":26,"tag":130,"props":10133,"children":10135},{"class":132,"line":10134},59,[10136],{"type":26,"tag":130,"props":10137,"children":10138},{},[10139],{"type":35,"value":10140},"    value = \"aws-elasticbeanstalk-ec2-role\"\n",{"type":26,"tag":130,"props":10142,"children":10144},{"class":132,"line":10143},60,[10145],{"type":26,"tag":130,"props":10146,"children":10147},{},[10148],{"type":35,"value":8892},{"type":26,"tag":130,"props":10150,"children":10152},{"class":132,"line":10151},61,[10153],{"type":26,"tag":130,"props":10154,"children":10155},{},[10156],{"type":35,"value":10035},{"type":26,"tag":130,"props":10158,"children":10160},{"class":132,"line":10159},62,[10161],{"type":26,"tag":130,"props":10162,"children":10163},{},[10164],{"type":35,"value":10043},{"type":26,"tag":130,"props":10166,"children":10168},{"class":132,"line":10167},63,[10169],{"type":26,"tag":130,"props":10170,"children":10171},{},[10172],{"type":35,"value":10051},{"type":26,"tag":130,"props":10174,"children":10176},{"class":132,"line":10175},64,[10177],{"type":26,"tag":130,"props":10178,"children":10179},{},[10180],{"type":35,"value":10059},{"type":26,"tag":130,"props":10182,"children":10184},{"class":132,"line":10183},65,[10185],{"type":26,"tag":130,"props":10186,"children":10187},{},[10188],{"type":35,"value":8892},{"type":26,"tag":130,"props":10190,"children":10192},{"class":132,"line":10191},66,[10193],{"type":26,"tag":130,"props":10194,"children":10195},{},[10196],{"type":35,"value":10035},{"type":26,"tag":130,"props":10198,"children":10200},{"class":132,"line":10199},67,[10201],{"type":26,"tag":130,"props":10202,"children":10203},{},[10204],{"type":35,"value":10205},"    namespace = \"aws:elasticbeanstalk:application:environment\"\n",{"type":26,"tag":130,"props":10207,"children":10209},{"class":132,"line":10208},68,[10210],{"type":26,"tag":130,"props":10211,"children":10212},{},[10213],{"type":35,"value":10214},"    name = \"SPRING_PROFILES_ACTIVE\"\n",{"type":26,"tag":130,"props":10216,"children":10218},{"class":132,"line":10217},69,[10219],{"type":26,"tag":130,"props":10220,"children":10221},{},[10222],{"type":35,"value":10223},"    value = \"prod\"\n",{"type":26,"tag":130,"props":10225,"children":10227},{"class":132,"line":10226},70,[10228],{"type":26,"tag":130,"props":10229,"children":10230},{},[10231],{"type":35,"value":8892},{"type":26,"tag":130,"props":10233,"children":10235},{"class":132,"line":10234},71,[10236],{"type":26,"tag":130,"props":10237,"children":10238},{},[10239],{"type":35,"value":10035},{"type":26,"tag":130,"props":10241,"children":10243},{"class":132,"line":10242},72,[10244],{"type":26,"tag":130,"props":10245,"children":10246},{},[10247],{"type":35,"value":10205},{"type":26,"tag":130,"props":10249,"children":10251},{"class":132,"line":10250},73,[10252],{"type":26,"tag":130,"props":10253,"children":10254},{},[10255],{"type":35,"value":10256},"    name = \"SPRING_DATASOURCE_URL\"\n",{"type":26,"tag":130,"props":10258,"children":10260},{"class":132,"line":10259},74,[10261],{"type":26,"tag":130,"props":10262,"children":10263},{},[10264],{"type":35,"value":10265},"    value = \"jdbc:mysql://${aws_db_instance.rds-db.endpoint}/${aws_db_instance.rds-db.name}?useSSL=false\"\n",{"type":26,"tag":130,"props":10267,"children":10269},{"class":132,"line":10268},75,[10270],{"type":26,"tag":130,"props":10271,"children":10272},{},[10273],{"type":35,"value":8892},{"type":26,"tag":130,"props":10275,"children":10277},{"class":132,"line":10276},76,[10278],{"type":26,"tag":130,"props":10279,"children":10280},{},[10281],{"type":35,"value":10035},{"type":26,"tag":130,"props":10283,"children":10285},{"class":132,"line":10284},77,[10286],{"type":26,"tag":130,"props":10287,"children":10288},{},[10289],{"type":35,"value":10205},{"type":26,"tag":130,"props":10291,"children":10293},{"class":132,"line":10292},78,[10294],{"type":26,"tag":130,"props":10295,"children":10296},{},[10297],{"type":35,"value":10298},"    name = \"SPRING_DATASOURCE_USERNAME\"\n",{"type":26,"tag":130,"props":10300,"children":10302},{"class":132,"line":10301},79,[10303],{"type":26,"tag":130,"props":10304,"children":10305},{},[10306],{"type":35,"value":10307},"    value = aws_db_instance.rds-db.username\n",{"type":26,"tag":130,"props":10309,"children":10311},{"class":132,"line":10310},80,[10312],{"type":26,"tag":130,"props":10313,"children":10314},{},[10315],{"type":35,"value":8892},{"type":26,"tag":130,"props":10317,"children":10319},{"class":132,"line":10318},81,[10320],{"type":26,"tag":130,"props":10321,"children":10322},{},[10323],{"type":35,"value":10035},{"type":26,"tag":130,"props":10325,"children":10327},{"class":132,"line":10326},82,[10328],{"type":26,"tag":130,"props":10329,"children":10330},{},[10331],{"type":35,"value":10205},{"type":26,"tag":130,"props":10333,"children":10335},{"class":132,"line":10334},83,[10336],{"type":26,"tag":130,"props":10337,"children":10338},{},[10339],{"type":35,"value":10340},"    name = \"SPRING_DATASOURCE_PASSWORD\"\n",{"type":26,"tag":130,"props":10342,"children":10344},{"class":132,"line":10343},84,[10345],{"type":26,"tag":130,"props":10346,"children":10347},{},[10348],{"type":35,"value":10349},"    value = aws_db_instance.rds-db.password\n",{"type":26,"tag":130,"props":10351,"children":10353},{"class":132,"line":10352},85,[10354],{"type":26,"tag":130,"props":10355,"children":10356},{},[10357],{"type":35,"value":8892},{"type":26,"tag":130,"props":10359,"children":10361},{"class":132,"line":10360},86,[10362],{"type":26,"tag":130,"props":10363,"children":10364},{},[10365],{"type":35,"value":10035},{"type":26,"tag":130,"props":10367,"children":10369},{"class":132,"line":10368},87,[10370],{"type":26,"tag":130,"props":10371,"children":10372},{},[10373],{"type":35,"value":10043},{"type":26,"tag":130,"props":10375,"children":10377},{"class":132,"line":10376},88,[10378],{"type":26,"tag":130,"props":10379,"children":10380},{},[10381],{"type":35,"value":10382},"    name = \"SecurityGroups\"\n",{"type":26,"tag":130,"props":10384,"children":10386},{"class":132,"line":10385},89,[10387],{"type":26,"tag":130,"props":10388,"children":10389},{},[10390],{"type":35,"value":10391},"    value = aws_security_group.eb-sg.id\n",{"type":26,"tag":130,"props":10393,"children":10395},{"class":132,"line":10394},90,[10396],{"type":26,"tag":130,"props":10397,"children":10398},{},[10399],{"type":35,"value":8892},{"type":26,"tag":130,"props":10401,"children":10403},{"class":132,"line":10402},91,[10404],{"type":26,"tag":130,"props":10405,"children":10406},{},[10407],{"type":35,"value":10035},{"type":26,"tag":130,"props":10409,"children":10411},{"class":132,"line":10410},92,[10412],{"type":26,"tag":130,"props":10413,"children":10414},{},[10415],{"type":35,"value":10416},"    namespace = \"aws:ec2:vpc\"\n",{"type":26,"tag":130,"props":10418,"children":10420},{"class":132,"line":10419},93,[10421],{"type":26,"tag":130,"props":10422,"children":10423},{},[10424],{"type":35,"value":10425},"    name      = \"VPCId\"\n",{"type":26,"tag":130,"props":10427,"children":10429},{"class":132,"line":10428},94,[10430],{"type":26,"tag":130,"props":10431,"children":10432},{},[10433],{"type":35,"value":10434},"    value     = module.vpc._.vpc_id\n",{"type":26,"tag":130,"props":10436,"children":10438},{"class":132,"line":10437},95,[10439],{"type":26,"tag":130,"props":10440,"children":10441},{},[10442],{"type":35,"value":8892},{"type":26,"tag":130,"props":10444,"children":10446},{"class":132,"line":10445},96,[10447],{"type":26,"tag":130,"props":10448,"children":10449},{},[10450],{"type":35,"value":10035},{"type":26,"tag":130,"props":10452,"children":10454},{"class":132,"line":10453},97,[10455],{"type":26,"tag":130,"props":10456,"children":10457},{},[10458],{"type":35,"value":10416},{"type":26,"tag":130,"props":10460,"children":10462},{"class":132,"line":10461},98,[10463],{"type":26,"tag":130,"props":10464,"children":10465},{},[10466],{"type":35,"value":10467},"    name      = \"Subnets\"\n",{"type":26,"tag":130,"props":10469,"children":10471},{"class":132,"line":10470},99,[10472],{"type":26,"tag":130,"props":10473,"children":10474},{},[10475],{"type":35,"value":10476},"    value     = module.vpc._.subnet_a\n",{"type":26,"tag":130,"props":10478,"children":10480},{"class":132,"line":10479},100,[10481],{"type":26,"tag":130,"props":10482,"children":10483},{},[10484],{"type":35,"value":8892},{"type":26,"tag":130,"props":10486,"children":10488},{"class":132,"line":10487},101,[10489],{"type":26,"tag":130,"props":10490,"children":10491},{},[10492],{"type":35,"value":10035},{"type":26,"tag":130,"props":10494,"children":10496},{"class":132,"line":10495},102,[10497],{"type":26,"tag":130,"props":10498,"children":10499},{},[10500],{"type":35,"value":10416},{"type":26,"tag":130,"props":10502,"children":10504},{"class":132,"line":10503},103,[10505],{"type":26,"tag":130,"props":10506,"children":10507},{},[10508],{"type":35,"value":10509},"    name = \"VPCId\"\n",{"type":26,"tag":130,"props":10511,"children":10513},{"class":132,"line":10512},104,[10514],{"type":26,"tag":130,"props":10515,"children":10516},{},[10517],{"type":35,"value":10518},"    value = module.vpc._.vpc_id\n",{"type":26,"tag":130,"props":10520,"children":10522},{"class":132,"line":10521},105,[10523],{"type":26,"tag":130,"props":10524,"children":10525},{},[10526],{"type":35,"value":8892},{"type":26,"tag":130,"props":10528,"children":10530},{"class":132,"line":10529},106,[10531],{"type":26,"tag":130,"props":10532,"children":10533},{},[10534],{"type":35,"value":10035},{"type":26,"tag":130,"props":10536,"children":10538},{"class":132,"line":10537},107,[10539],{"type":26,"tag":130,"props":10540,"children":10541},{},[10542],{"type":35,"value":10416},{"type":26,"tag":130,"props":10544,"children":10546},{"class":132,"line":10545},108,[10547],{"type":26,"tag":130,"props":10548,"children":10549},{},[10550],{"type":35,"value":10551},"    name = \"AssociatePublicIpAddress\"\n",{"type":26,"tag":130,"props":10553,"children":10555},{"class":132,"line":10554},109,[10556],{"type":26,"tag":130,"props":10557,"children":10558},{},[10559],{"type":35,"value":10560},"    value = \"true\"\n",{"type":26,"tag":130,"props":10562,"children":10564},{"class":132,"line":10563},110,[10565],{"type":26,"tag":130,"props":10566,"children":10567},{},[10568],{"type":35,"value":8892},{"type":26,"tag":130,"props":10570,"children":10572},{"class":132,"line":10571},111,[10573],{"type":26,"tag":130,"props":10574,"children":10575},{},[10576],{"type":35,"value":380},{"type":26,"tag":38,"props":10578,"children":10580},{"id":10579},"deploy-infrastructure",[10581],{"type":35,"value":10582},"Deploy infrastructure",{"type":26,"tag":31,"props":10584,"children":10585},{},[10586],{"type":35,"value":10587},"With terraform, only we need to do is execute the following command, providing a file with all the variables we have defined",{"type":26,"tag":121,"props":10589,"children":10591},{"className":2561,"code":10590,"language":2560,"meta":8,"style":8},"terraform apply -var-file=\"test.tfvars\"\n",[10592],{"type":26,"tag":15,"props":10593,"children":10594},{"__ignoreMap":8},[10595],{"type":26,"tag":130,"props":10596,"children":10597},{"class":132,"line":133},[10598,10602,10607,10612],{"type":26,"tag":130,"props":10599,"children":10600},{"style":154},[10601],{"type":35,"value":8745},{"type":26,"tag":130,"props":10603,"children":10604},{"style":165},[10605],{"type":35,"value":10606}," apply",{"type":26,"tag":130,"props":10608,"children":10609},{"style":194},[10610],{"type":35,"value":10611}," -var-file=",{"type":26,"tag":130,"props":10613,"children":10614},{"style":165},[10615],{"type":35,"value":10616},"\"test.tfvars\"\n",{"type":26,"tag":27,"props":10618,"children":10619},{},[10620],{"type":26,"tag":31,"props":10621,"children":10622},{},[10623],{"type":26,"tag":8186,"props":10624,"children":10625},{},[10626,10628],{"type":35,"value":10627},"You can find the complete code of this example in this ",{"type":26,"tag":903,"props":10629,"children":10632},{"href":10630,"target":10631},"https://github.com/JaimeDeArcos/terraform-aws-archetype","_blank",[10633],{"type":35,"value":10634},"GitHub repository",{"type":26,"tag":932,"props":10636,"children":10637},{},[10638],{"type":35,"value":936},{"title":8,"searchDepth":176,"depth":176,"links":10640},[10641,10642,10643,10644,10645],{"id":8761,"depth":176,"text":8764},{"id":8781,"depth":176,"text":8784},{"id":9234,"depth":176,"text":9237},{"id":9667,"depth":176,"text":9670},{"id":10579,"depth":176,"text":10582},"content:posts:manage-aws-infrastructure-with-terraform.md","posts/manage-aws-infrastructure-with-terraform.md","posts/manage-aws-infrastructure-with-terraform",1790510064589]