The issues with Java threads in the question are addressed by the project Loom, which is now included in Jdk21. It is very well explained here https://www.baeldung.com/openjdk-project-loom :
Presently, Java relies on OS implementations for both the continuation [of threads] and the scheduler [for threads].
Now, in order to suspend a continuation, it's required to store the entire call-stack. And similarly, retrieve the call-stack on resumption. Since the OS implementation of continuations includes the native call stack along with Java's call stack, it results in a heavy footprint.
A bigger problem, though, is the use of OS scheduler. Since the scheduler runs in kernel mode, there's no differentiation between threads. And it treats every CPU request in the same manner. (...) For example, consider an application thread which performs some action on the requests and then passes on the data to another thread for further processing. Here, it would be better to schedule both these threads on the same CPU. But since the [OS] scheduler is agnostic to the thread requesting the CPU, this is impossible to guarantee.
The question really boils down to Why are OS threads considered expensive?
Answer from Albert Hendriks on Stack OverflowHey everyone,
I’m currently in the middle of my 4th year of engineering and trying to decide which backend technology to focus on — Java Spring Boot or Python FastAPI. I’ve been doing mobile app development (Flutter) for quite some time, but since most startups use Flutter and the pay isn’t that great, I want to explore backend development for better opportunities.
Here’s my situation and confusion 👇
-
Java Spring Boot seems tougher to learn than Python FastAPI.
-
However, most MNCs and enterprise companies use Spring Boot.
-
With AI and ML booming, many modern companies are starting to adopt FastAPI because of Python’s ecosystem.
-
I’ve already bought a paid Spring Boot course (worth ₹8,000) that covers backend from 0→1 (8 weeks) and 1→100 (9 weeks).
-
I also found a free 12-hour FastAPI course on YouTube that looks great.
-
My placement season is ongoing, so I don’t have unlimited time.
-
I have strong frontend (Flutter) skills but very little backend experience.
-
I feel getting placed in startups is easier, but the pay is lower compared to MNCs.
-
The main reason I’m pausing Flutter is that it’s used mostly by startups and the compensation isn’t very attractive.
Given all this, I’m really confused — 👉 Should I go with Java + Spring Boot (for better placement options and MNC exposure)? 👉 Or with Python + FastAPI (for faster learning and alignment with AI/startup ecosystem)?
I’d love to hear from people who’ve been in similar situations or are working in backend roles — Which one should I choose and why, given my current context (final year + Flutter background + placements)?
FastAPI vs Spring Boot / NestJS for scalable, AI-driven SaaS backends?
FastAPI vs Springboot
Best Framework for Handling High Traffic: Spring Boot, .NET, or Go?
FastAPI, still in high demand?
Videos
The issues with Java threads in the question are addressed by the project Loom, which is now included in Jdk21. It is very well explained here https://www.baeldung.com/openjdk-project-loom :
Presently, Java relies on OS implementations for both the continuation [of threads] and the scheduler [for threads].
Now, in order to suspend a continuation, it's required to store the entire call-stack. And similarly, retrieve the call-stack on resumption. Since the OS implementation of continuations includes the native call stack along with Java's call stack, it results in a heavy footprint.
A bigger problem, though, is the use of OS scheduler. Since the scheduler runs in kernel mode, there's no differentiation between threads. And it treats every CPU request in the same manner. (...) For example, consider an application thread which performs some action on the requests and then passes on the data to another thread for further processing. Here, it would be better to schedule both these threads on the same CPU. But since the [OS] scheduler is agnostic to the thread requesting the CPU, this is impossible to guarantee.
The question really boils down to Why are OS threads considered expensive?
FastAPI is a fast framework, and you can quickly (and easily) create API backends in it. To be honest, if you are a Java developer, I would recommend Quarkus or something for building a REST API, not FastAPI. FastAPI is a fantastic tool, absolutely great if you are already in the Python ecosystem.
When it goes about multithreading; Java is 'real' multithreading where as Python is very much not. Java threads will run concurrently; two tasks can and will be executed at the same time. In Python, within one Python process, this is (nearly) impossible. The reason for this is GIL (google it, there is ton's of stuff out there on how it works). The result is; even if you use 'real' threads in Python, code is still not executed concurrently but rather serially, where the interpreter (big difference to Java) is jumping from one call stack to another constantly.
As to what you refer to as 'logical threads', I think you mean the asynchronous capability of Python. This is basically the same as using threads (not really, but on an abstract level they are very similar); tasks are not run concurrently. There is just one thread that constantly switches between tasks. Tasks will yield back control to the event loop (the object that coordinates tasks and decides what is executed in which order), and another task is further executed until that task yields control, etc. It is basically the same kind of execution pattern as with threads within Python.
Comparing a Python framework to a Java framework is just weird in my opinion. They are both useful and cool, but not really competitors.
Hey all,
I’m planning to build scalable SaaS products (with AI features) and I’m trying to decide which backend stack to go all-in on.
I’ve worked with Spring Boot before — it’s powerful and full-featured, but sometimes feels like overkill for fast-moving startup projects. On the other hand, FastAPI seems super lightweight and productive, but I keep hearing it lacks a lot of built-in features meaning you end up wiring a lot of things yourself.
Would you recommend fastAPI for building scalable AI saas platforms, or is it better to stick with something more structured like Spring Boot or NestJS?
I'm working at a company where most systems are developed using FastAPI, with some others built on Java Spring Boot. The main reason for using FastAPI is that the consultancy responsible for many of these projects always chooses it.
Recently, the coordinator asked me to evaluate whether we should continue with FastAPI or move to Spring Boot for all new projects. I don't have experience with FastAPI or Python in the context of microservices, APIs, etc.
I don't want to jump to conclusions, but it seems to me that FastAPI is not as widely adopted in the industry compared to Spring Boot.
Do you have any thoughts on this? If you could choose between FastAPI and Spring Boot, which one would you pick and why?