Thread in Java and NodeJs

3

We know that benchmarks are specific measures and do not count for all cases, certainly what and how you measure matters a lot, so I'll try to be very specific.

In the case of a server having thousands of connections, and if it is a thread running concurrently, while the node is asynchronous, in this environment would we gain performance by using nodeJs?

Another question in the matter, is java able to work the threads asynchronously?

    
asked by anonymous 17.08.2015 / 22:20

1 answer

3

TL; DR

Yes, in a highly concurrent, resource-sharing environment, an asynchronous (event-based) model may have advantages over a thread-based parallel.

Yes, java is able to work asynchronously.

Competitor x Asynchronous

The competing model is not a problem in itself. It is best 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 waiting for external resources, ie input and output.

In this scenario, parallelism does not help at all. Thousands of locked threads waiting their turn to change a locked table is a huge waste of memory and processing of the scheduler. A thread processing a queue makes better use of resources.

Asynchronous support in Java

Java has long supported asynchronous input and output (package java.nio ), but only since Servlet 3.0 has first-class support for the asynchronous request-manipulation 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, understanding the architecture in which it works. This simply does not happen in most cases.

The advantage of Java is that it has evolved moderately over the years, virtually without breaking API compatibility and, at the same time, allowing the development of high-end applications (albeit with a delay time compared to other languages ).

In addition, as long as you know what you're doing, Java gives you the flexibility to work on the most appropriate model for each situation.

Well consider that all this is relevant in applications that have high competition. On most systems where there are no more than tens or even hundreds of threads, any optimization in this direction will not be as relevant.

    
18.08.2015 / 03:09