August 29, 2019

'Nazar' actor Harsh Rajput felicitated for his excellence!

Harsh Rajput, who is currently enthralling the audience with his brilliant performance in Gul Khan's popular show Nazar, turned nostalgic after getting felicitated by Mumbai University for his contribution in the field of acting.

August 27, 2019

Part 10: Reentrant Locks

What are Reentrant Locks?
  • ReentrantLock in Java is added on java.util.concurrent package in Java 1.5 along with other concurrent utilities like CountDownLatch, Executors and CyclicBarrier.
  • ReentrantLock is a concrete implementation of Lock interface provided in Java concurrency package from Java 1.5 onwards. 
  • Reentrant Locks are provided in Java to provide synchronization with greater flexibility.
  • The code which manipulates the shared resource is surrounded by calls to lock and unlock method. This gives a lock to the current working thread and blocks all other threads which are trying to take a lock on the shared resource.
  • A ReentrantLock allow threads to enter into lock on a resource more than once. When the thread first enters into lock, a hold count is set to one. Before unlocking the thread can re-enter into lock again and every time hold count is incremented by one. For every unlock request, hold count is decremented by one and when hold count is 0, the resource is unlocked.
  • Fairness  parameter is provided while creating instance of ReentrantLock in constructor. 
  • ReentrantLock provides same visibility and ordering guarantee, provided by implicitly locking, which means, unlock() happens before another thread get lock().
  • If you forget to call the unlock() method in the finally block, it will lead to bugs in the program. Make sure that the lock is released before the thread exits.
  • The fairness parameter used to construct the lock object decreases the throughput of the program.

Difference between ReentrantLock and synchronized keyword in Java
  1. We can achieve thread synchronization in Java by using the 'synchronized' keyword. While it provides a certain basic synchronization, the synchronized keyword is quite rigid in its use. e.g, a thread can take a lock only once. Synchronized blocks don’t offer any mechanism of a waiting queue and after the exit of one thread, any thread can take the lock. This could lead to starvation of resources for some other thread for a very long period of time. ReentrantLock provides a method called lockInterruptibly(), which can be used to interrupt thread when it is waiting for lock. Similarly tryLock() with timeout can be used to timeout if lock is not available in certain time period.
  2. Fairness property provides lock to longest waiting thread, in case of contention. synchronized keyword doesn't support fairness. Any thread can acquire lock once released, no preference can be specified. ReentrantLock fair by specifying fairness property, while creating instance of ReentrantLock. 
  3. ReentrantLock provides convenient tryLock() method, which acquires lock only if its available or not held by any other thread. This reduce blocking of thread waiting for lock in Java application. This is not possible in case of synchronized keyword.
  4. ReentrantLock also provides convenient method to get List of all threads waiting for lock. We can create different conditions for Lock and different thread can await() for different conditions.
  5. Synchronization code is much cleaner and easy to maintain whereas with Lock we are forced to have try-finally block to make sure Lock is released even if some exception is thrown between lock() and unlock() method calls.
  6. synchronization blocks or methods can cover only one method whereas we can acquire the lock in one method and release it in another method with Lock API.
ALSO CHECKAll About Java Threads

-K Himaanshu Shuklaa..

Part 9: Java Thread Interview Questions & Answers (All About Java Semaphore and Mutex)

Why we need Semaphore?
  • Lets say our application calls a service, which is quite slow. Because the service is slow, at a time only 5 calls can be made.
  • Now lets say their are 50 threads present in the application, and they all try to access the service. We need a mechanism, by which we can restrict the call to slow service. This can be achieved using Semaphore.
  • A Semaphore will act as a layer, with a limited number of permits (in our case permits=5). 
  • Now thread 1 wants to access the service, it will call acquire() method to get the permit. Semaphore will check number of available permits (in our case its 5), if its available it will give permit to thread 1 and then decrements the permit by 1 (now the permit=4).
  • While thread 1 is accessing the slow service, thread 2 comes. The Semaphore again checks available permit (which is 4) and give it to thread 2.
  • Lets say thread 3, 4 and 5 comes and get the permit. While these 5 threads are accessing the slow service thread 6 comes, since now the permit is 0 Semaphore will block the thread 6.
  • In the meanwhile, Thread 1 completes the work from slow service, it will call release() method. The release() method will increment the permit(which was 0) by 1. Now the permit is 1, the Semaphore gives the access to Thread 6 and decrements the permit (new value will be 0).

August 21, 2019

Ullu App ready to make web-series in Bangla

Ullu is India’s one of the popular OTT platforms with more than 4 million mobile downloads and is available in over 100 countries. The digital platform currently offers Hindi web-series across various genres, which are dubbed in regional languages like Marathi, Bhojpuri, Bangla, Telgu etc. Now, Ullu is all set to embark a new journey and will soon start producing web-series in regional languages starting with Bangla.

When contacted Vibhu Agarwal, CEO at Ullu Digital Pvt Ltd, told us, "We have received amazing feedback for our web-series like Singardan, Halala, Panchali from the regional viewers. Since regional content is the demand of the hour, we are planning to create original content in regional languages on topics that resonate with regional culture and viewers."

Ullu will start exploring the regional market with a bang by producing dozens of web-series in Bangla. Confirming the same Vibhu said, "Bengal has a rich and vibrant culture, which always fascinates me. That's the reason, we are starting our regional debut with Bangla web-series. We are planning to come up with more than 25 web-series within a year."

He further added, "There is a phenomenal amount of talent in Bengal, which we want to utilize. We are looking forward to work with the regional artists and shoot in the exotic locals of West Bengal and Bangladesh."

For those uninitiated, popular Bengali actor Riju Biswas, who has done several Bengali TV serials like Checkmate, Tomay Amay Mile (the Bengali adaptation of popular Hindi show Diya Aur Baati Hum), and Bou Kotha Kao is playing the lead role in Ullu's upcoming web-series 'Size Matters'.  

August 01, 2019

Bulley Shah's 'Rab Rab Karde Budhe Hoo Gaye' Meaning In English..

रब-रब करदे बुड्ढे हो गए, मुल्ला पंडित सारे.  
रब दा खोज खरा न लब्बा, सजदे कर कर हारे..
RSSChomp Blog Directory