It’s a topic which every
developer faces now a day. Every architect or developer having experience in
java always reluctant to go for node.js and prefer java. Before inclining
towards any language we need to understand the basic fundamental of that
language. Understanding of basics will help us to find suitable language for
our server which can fulfill our requirements best. The basic nature of java and
node.js is different in way they handle the requests.
Java is multi-threaded
language where requests can be entertained by multiple threads so it uses the
processor in better way. The basic programming nature of java in Synchronous.
If it is executing a code, then it waits for its finish before going to next
line of code. In simple words let’s take an example that we have two block of
codes where in first block we have a HTTPS call and in second block we have
code which logs a message in log file. The HTTPS call takes 5 seconds on an
average so java code will wait on first code block for 5 seconds to receive the
response and complete that call before proceed to second block which make the
whole process a bit slow.
We can consider node.js as single
thread language where whole application uses a single thread to fulfill all the
requests on queue base architecture. All required actions are stored in queue
and executed by single thread. The basic programming nature of node.js is asynchronous.
If it is executing a code, then it does not wait for its finish before going to
next line of code. In same example which we took for java that we have two block
of codes where in first block we have a HTTPS call and in second block we have
code which logs a message in log file. The HTTPS call takes 5 seconds on an
average so node.js code will not wait on first code block for 5 seconds to
receive the response and complete that call rather it execute it and proceed to
second block the action which we require on response of first call is also queued.
Node.js inherit
this Asynchronous feature from JavaScript which makes it suitable for developing high
IO operation, data intensive, non-blocking applications like Web-servers and
node.js is not suited for application
where high calculation, complex business
logic or processor intensive operation are required as it has single thread
which can get busy for executing that calculation.
No comments:
Post a Comment