🚀 Runnable vs Callable — The Threading Showdown You Didn’t Know You Needed! Ever wondered why Java gave us both Runnable and Callable? Let’s simplify 👇 1. Runnable came first — old school, reliable. 2. Callable came later — smarter, more flexible. 3. Runnable’s run() → does the job, returns nothing. 4. Callable’s call() → does the job and gives you something back 💡 5. Runnable says: “I’ll just run.” 6. Callable says: “I’ll run, and I’ve got results for you!” 💼 7. Runnable can’t throw checked exceptions ❌ 8. Callable can ✅ 9. Use Runnable when you just want action. 10. Use Callable when you want answers. 11. Runnable = Fire & Forget 🔥 12. Callable = Fire & Collect 🎯 13. ExecutorService.submit(Callable) → gives you a Future. 14. Future = the promise of a result, not now, but soon ⏳ 15. Runnable walks… 16. Callable runs 🏃♂️💨 Next time you build a multithreaded app, choose wisely — and code like a pro ⚙️✨ 💾 Save this post for your next concurrency project 🤝 Follow for more Java insights #Java #Coding #Multithreading #Developers #TechTips #Programming #CodeBetter
Java Threading: Runnable vs Callable - A Comparison
More Relevant Posts
-
👋 Hi Everyone Day 79 of my 100 Days of Java Full Stack Challenge! Today, I learned about Constructor-based Dependency Injection and the use of @Qualifier annotation in Spring Boot. I implemented this concept by injecting dependencies explicitly when multiple bean implementations were available for a single interface. 🧩 What I Learned 1️⃣ Constructor-Based Dependency Injection 👉 In Spring Boot, we can inject dependencies not only using the @Autowired annotation but also directly through the constructor. 👉 This approach makes the dependencies immutable, improves testability, and is highly recommended by Spring for cleaner and safer code. 2️⃣ @Qualifier Annotation 👉 The @Qualifier annotation is used when there are multiple beans of the same type, and we need to tell Spring which one to inject. 👉 In this example, both Laptop and Desktop implement the Computer interface. 👉 By specifying @Qualifier("laptop"), Spring injects the Laptop bean instead of Desktop. 💡 Key Point: ✅ Use @Primary when you have a common default choice. ✅ Use @Qualifier when you want fine-grained control over which implementation to inject. 4️⃣ Application Flow Summary Spring Boot scans and creates beans for Laptop, Desktop, and Developer. The Developer constructor expects a Computer type bean. Using @Qualifier("laptop"), Spring injects the Laptop bean. When developer.startCoding() is called, it prints: 👉 “Coding in Laptop…” 💡 Result: ✔ Constructor Injection ensures strong immutability. ✔ @Qualifier ensures precise control when multiple beans exist. ✔ Code becomes clean, modular, and easily maintainable. 🙏 A big thanks to #Codegnan and my mentor #AnandKumarBuddarapu sir for clearly explaining the difference between @Primary and @Qualifier through practical demonstrations. Special thanks to #UppugundlaSairam sir and #SaketKallepu sir for their continuous support and encouragement in my learning journey. #100DaysOfJavaFullStack #SpringBoot #DependencyInjection #Qualifier #Primary #ConstructorInjection #SpringFramework #IoCContainer #JavaDeveloper #LearningJourney #Codegnan
To view or add a comment, sign in
-
Just wrapped up another solid Java concept today — the difference between String, StringBuilder, and StringBuffer 🔥 This one might look simple, but understanding mutability, thread-safety, and performance makes a huge difference in writing efficient code. Here’s the quick takeaway - String ➜ Immutable, thread-safe, but slower for repeated modifications. - StringBuilder ➜ Mutable, fastest, best for single-threaded operations. - StringBuffer ➜ Mutable, thread-safe, suitable for multi-threaded use. Every small concept like this builds the foundation for becoming a strong Java full-stack developer Big thanks to my mentor Anand Kumar Buddarapu for guiding me through this — learning gets easier when you have the right support #Java #Coding #String #StringBuilder #StringBuffer #Codegnan #LearningJourney #FullStackDevelopment
To view or add a comment, sign in
-
-
⚔️ '𝐓𝐢𝐬 𝐓𝐡𝐞 𝐁𝐚𝐭𝐭𝐥𝐞 𝐨𝐟 𝐭𝐡𝐞 𝐁𝐚𝐜𝐤𝐞𝐧𝐝𝐬! Ever wondered what it would look like if Node.js, Django and FastAPI, Spring Boot, and Go stepped into the same arena? My latest post on 𝐬𝐞𝐚 𝐨𝐟 𝐤𝐧𝐨𝐰𝐥𝐞𝐝𝐠𝐞 explores that fight. A clash of speed, structure, and sanity. From Java’s enterprise tanks to Go’s silent assassins, this one’s for anyone who’s switched tech stacks more times than they can count. 💡 After all the rounds, I’ve realized it’s rarely about which backend is “best". Read the full piece here 👉 https://lnkd.in/dhfgFRdh #BackendDevelopment #SystemDesign #Programming #TechBlog #LearningInPublic #SoftwareEngineering
To view or add a comment, sign in
-
-
🔥 Spring Boot Made Simple! Tired of scattered tutorials? I’ve packed everything you need about Spring Boot — setup, annotations, CRUD, REST APIs & real-world examples — into one powerful PDF 💥 🎯 Perfect for Java Developers, Students & Backend Beginners 💾 Download it FREE below & start building like a pro! #SpringBoot #Java #BackendDevelopment #Coding #SoftwareEngineering
To view or add a comment, sign in
-
🧩 I still remember when my Spring Boot API refused to return JSON… I spent hours debugging, only to realize I used the wrong annotation. 😅 That day, I finally understood the difference between 👉 @Controller and @RestController And trust me — this tiny detail can make a big difference. So I turned that learning into a simple visual guide 👇 💡 In this carousel, you’ll learn: ✅ What each annotation actually does ✅ When to use one over the other ✅ And… the BIG question — 👉 What happens if you use both together? Hint: one silently wins the battle 👀 💬 Drop your guess in the comments! And share this if it helped you or your team avoid that “why is my JSON not returning?” moment 😅 #SpringBoot #Java #BackendDevelopment #Microservices #CodeTips #SoftwareEngineering #Developers #LearningInPublic #TechCommunity #Programming #CareerInTech #RestAPI
To view or add a comment, sign in
-
🧵 Callable & Future — The Day My Threads Started Talking Back 😅 Back when I first learned multithreading in Java, I thought Thread and Runnable were all I needed. “Just start a new thread, right?” — I said confidently. Until one day, I needed my thread to return a value. That’s when Java looked me in the eye and said: “Threads don’t talk back, buddy.” 😆 Enter Callable and Future — the real MVPs of concurrent programming. ⸻ 🔹 Runnable → fire and forget: ___________________________ new Thread(() -> doWork()).start(); ———————————- No return, no clue what happened. 🔹 Callable + Future → “run and tell me later”: _______________________ ExecutorService executor = Executors.newFixedThreadPool(2); Future<Integer> future = executor.submit(() -> { Thread.sleep(1000); return 42; }); System.out.println(future.get()); // waits and prints 42 ———————— ✅ Callable returns a result. ✅ Future lets you check status, cancel tasks, or wait for completion. ⸻ 💡 Where it shines: • Fetching data from multiple APIs in parallel • Background computations • Tasks where you actually need the result But beware 👀 — future.get() blocks the thread until the result is ready. So don’t overuse it — or your “asynchronous” code becomes synchronous again 😂 ⸻ 💭 My takeaway: If Runnable is your intern who never reports back, then Callable + Future is your responsible teammate who always emails the result 📬 Have you ever combined Callable with ExecutorService in your projects? Or moved on to CompletableFuture already? 😎 #Java #Concurrency #Multithreading #BackendDevelopment #SpringBoot #Callable #Future
To view or add a comment, sign in
-
Why the final Keyword Is Underrated in Java ? Most developers use final only when the compiler forces them to. But the truth is , final isn’t just about restriction, it’s about clarity. When you mark a variable, method, or class as final, you’re making a statement: “This part of the code is not meant to change.” That single keyword communicates intent - it reduces side effects, improves readability, and makes debugging easier. In large projects, where multiple developers touch the same codebase, that clarity becomes gold. We often chase new frameworks and fancy tools... but sometimes, it’s the small things like final that keep our systems stable. “Good developers write code that works.” “Great developers write code that stays consistent.” #Java #CleanCode #Programming #SoftwareEngineering #BackendDevelopment #CodeQuality #CodingBestPractices #DeveloperTips #SoftwareDevelopment #TechCommunity
To view or add a comment, sign in
-
-
🪞 Ever wondered how Java can “look at itself”? That’s where Java Reflection comes in — a powerful feature that lets you inspect and even modify classes, methods, and fields at runtime. Whether you’re building frameworks, debugging tools, or dependency injectors like Spring — reflection helps your code understand its own structure. 💡 It’s introspection in action — your program reflecting on itself! #Java #SpringBoot #Reflection #BackendDevelopment #Coding #TechLearning #Developers #ProgrammingConcepts
To view or add a comment, sign in
-
-
#DAY68 #100DaysOFCode | Java Full Stack Development #Day68 of my #100DaysOfCode – Java 📘 Cursor in Java A Cursor in Java is used to traverse elements of a collection one by one. It provides a way to access, remove, or modify elements during iteration. Cursors are mainly used in the Collection Framework for iterating over lists, sets, and legacy classes. 🔹 Types of Cursors in Java Enumeration Used with legacy classes like Vector and Hashtable. Can only move forward. Cannot add or remove elements. Methods: hasMoreElements() – checks for next element nextElement() – returns next element Iterator Works with all collection classes. Can move only forward. Allows removal of elements during iteration. Methods: hasNext() next() remove() ListIterator Used only with List classes (ArrayList, LinkedList). Can move both forward and backward. Allows add, remove, and modify operations. Methods: hasNext(), next() hasPrevious(), previous() add(), remove(), set() A big thanks to my mentor Gurugubelli Vijaya Kumar Sir and the 10000 Coders for constantly guiding me and helping me build a strong foundation in programming concepts. #Java #Coding #Programming #100DaysOfCode #Java #programming #CodeNewbie #LearnToCode #Developer #Tech #ProgrammingTips #JavaDeveloper #CodeDaily #DataStructures #CodingLife
To view or add a comment, sign in
-
-
Software engineers fighting over languages, frameworks and features, stop! End users don't care. Whenever faced with the temptation, pass. I've seen teams waste precious time over personal stuff instead of shipping features. Gradle is better than maven? Customer are waiting. Coroutines are fancier than Virtual Threads? Who cares. Should we use this or that framework? Customers don't care. Build products, satisfy customers, This is all what really matters. Instead of disagreeing over choice of technology, prioritize what customers really care about. #SoftwareDevelopnent #SoftwareEngineering #Java #Golang #Kotlin #JavaScript #Rust #TypeScript #Python #Programming #Web
To view or add a comment, sign in
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development