Concurrency in GUI applications

The hardware we have become accustomed to using has became more and more powerful with each passing year. Today, even the CPUs inside our smartphones have quad-core or octa-core configurations. These configurations allow the running of multiple processes or threads in parallel. Not exploiting the power of concurrency would be a waste of the hardware improvements mentioned previously. Today, when we open applications on our smartphones, most of them have two or more threads running, though we are unaware of that most of the time.

Let's consider a fairly simple example of opening up a photo gallery application on our device. As soon as we open the photo gallery, an application process is started. This process is responsible for loading up the GUI of the application. The GUI runs in the main thread and allows us to interact with the application. Now, this application also spawns another background thread, which is responsible for traversing through the filesystem of the OS and loading up the thumbnails of the photos. This loading up of thumbnails from the filesystem can be a tedious task and may take some time, depending on how many thumbnails need to be loaded.

Though we do notice that the thumbnails are slowly loading, throughout this whole time, our application GUI remains responsive and we can interact with it, see the progress, and so on. All of this is made possible through the use of concurrent programming.

Imagine if concurrency hadn't been used here. The application would have been loading the thumbnails in the main thread itself. This would have caused the GUI to become unresponsive until the main thread finished loading the thumbnails. Not only would this have been very unintuitive, it also would have caused a bad user experience, which we avoided with the help of concurrent programming.

Now we have a fair idea of how concurrent programming can prove to be of great use, let's see how it can help us with the design and development of enterprise applications and what can be achieved with it.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.34.226