Tuesday, August 7, 2018

BlockingQueue

Producer - consumer problem arises in multi thread environment. This can be defined when there are one or more threads generate data independently and same time one or many threads read those data to process independently.

To solve this we can have an array and there would be synchronized method to access. So when one thread only can either read/write at same time. If the array is full, producer threads need to wait. And if the array is empty consumer threads need to wait.

java.util.concurrent package comes with Blocking queue which is very handy to solve this problem.
Blocking queue is an interface. ArrayBlockingQueue  is an concrete implementation of interface. It allow both wait or fail for producer if the queue is full, same way for consumer it fails or waits if the queue is empty.

Some sample codes can be foundin https://github.com/pallabrath/myexpjava/tree/master/myexpjava/src/demo/blockingQueue

What we discussed here is in the scope of single instance. If we want scale then there would be more than one instance. In that case of distributed environment we need different kind of solution. Java message queue fit into this situation.

Again if we scale further and we want to process data in large volume, Kafka goes well in the distributed environment. Kafka itself run on one or many node to scale.

We will discuss Kafka in a separate thread.

Saturday, June 10, 2017

I too want to be cloud developer

In last few years cloud was one of those word which we developer hardly spend a day with out listening. In fact its becoming quite louder and in future we will see more software run in cloud. As a developer I always wonder cloud means what change in my design and coding. Any way my java program need a JVM whether its on premise or in cloud how does it change. Users will see my web app through a browser what changes if it served from a on premise web server or a cloud web server at the end we need a Java servlet container to run our server side code. So how will I adapt to this cloud computing ?

As I started seeing cloud from more close quarter, I can say with some minor tweaks we can leverage the power of cloud computing. While talking about the cloud the next word come to my mind is "elasticity". It means our IT resources like computing storage etc can seamlessly expand and contract based on the need. With out upfront H/W cost we will pay as we use and we will use as we need. This particular things bring down the cost of IT. So for a developer like us increase the scope of further imagination. We can have more storage and compute as we need.

To appreciate the elasticity nature of the cloud our software design should be truly distributed and loosely coupled. If the software is segregated in different independent component then its very easy for a particular component can scale to meet demand, which will be the most efficient use of resource. All these things are also popularly known as micro service architecture.

Another good thing is cloud vendors provide a lots of standard software building blocks and technique. So we can quickly turn around new features and software.

I believe that cloud will make software more affordable so that more people can use the power computing.

Sunday, April 9, 2017

Automation is boon or bane

"Automation" dictionary meaning is "the use or introduction of automatic equipment in a manufacturing or other process or facility. And the next line is ‘unemployment due to the spread of automation’. This word is quite old probably its in practice from 1940. So when we read lots of stories like impact of automation and job loss because of it, I wonder how this problem is not solved yet.
If we look back Human evolution, apart from the biological changes we are continuously improving tools and adapting to use them. So we invent and discover something lets say motor car. then we try to produce them in scale by setting up factory and establishing process. And slowly we delicate these task to different tools which are machine, robots and computers. In this process we force our fellow human from one form of job to another. So we always move to more productive things.

I belong to digital industry which thrives on the possibility of automation. Computers and software are catalyst for automation. After automating different industry now we are looking inside. It means IT will be more efficient in term of economy more people can afford and use.

For a developer perspective if we look beyond job risk, there are lots of possibilities are in horizon. Now all the development platform or systems are automatically provisioned. So we can have more servers, compute more storage to write and test our code. With test automation we will be more confident on our changes and quality. With automatic monitoring the health of our production system and software our systems will be more reliable. We are having smart editor which generate some part of code to assist developers. So in less time we can code more features.

My point is automation is a contentious process and an ultimate truth. The one who adapts it open to learn new productive way of doing always thrive.