TL;DR
Yes, in a highly concurrent resource-sharing environment, an asynchronous model (event-based) can have advantages over a parallel (thread-based).
Yes, java can work asynchronously.
Competitor x Asynchronous
The concurrent model is not a problem in itself. It is better when there is processing that can be done in parallel.
the problem starts because in most common web applications the largest amount of time is spent accessing and expecting external resources, ie input and output.
In this scenario parallelism does not help at all. Thousands of blocked threads waiting their turn to change a locked table is a huge waste of memory and scheduler processing. A thread processing a queue makes better use of resources.
Asynchronous support in Java
Java has long had asynchronous input and output support (package java.nio
), but only since Servlet 3.0 has first-class support for the asynchronous request handling model. See a very good article here (in English).
Considerations
The disadvantage of Java is that the programmer needs to explicitly use the new API and convert the legacy code by understanding well the architecture on which I work. It just doesn’t happen in most cases.
The advantage of Java is that it has evolved moderately far from the years virtually without breaking API compatibility and at the same time allowing the development of cutting-edge applications (albeit with a lag time compared to other languages).
Also, as long as you know what you’re doing, Java gives you the flexibility to work on the most suitable model for every situation.
Good to still consider that all this is relevant in applications that has high competition. In most systems where there are no more than tens or even hundreds of threads, any optimization in this sense will not be so relevant.
thanks, it was much clearer now, almost everything I researched was in English, so I can read half and understand half of what I read...
– SneepS NinjA