Posts

Showing posts from 2017

Styling in React Native

When you first jump into React Native, styling can seem a little confusing; it’s in JavaScript, it has some but not all features of css, certain styles can only be used on certain components, and the list goes on. I’m aiming to be of aid to the initial confusion. Instead of going too deep into how React Native styles work, I want to keep this post as pragmatic as possible. I’ll simply share some practical points that I would have wanted to know, prior to styling in React Native. – Use StyleSheet You can write your styles inline but that’s usually not the best idea. There are times to take advantage of inline styles but when in doubt, use StyleSheet,  import { StyleSheet } from 'react-native' . It’s often worth splitting your styles from your component code and importing them into your component. Using StyleSheet is an easy way to handle the maintainability of your front-end codebase. Too many inline styles will cause bloated component code and unfortunately you can’t just...

Java Thread – Mutex and Semaphore example

Java multi threads example to show you how to use Semaphore and Mutex to limit the number of threads to access resources. Semaphores – Restrict the number of threads that can access a resource. Example, limit max 10 connections to access a file simultaneously. Mutex – Only one thread to access a resource at once. Example, when a client is accessing a file, no one else should have access the same file at the same time. 1. Semaphore Consider an ATM cubicle with 4 ATMs, Semaphore can make sure only 4 people can access simultaneously. import java.util.concurrent.Semaphore; import java.util.stream.IntStream; /** * * @author Amila Silva * */ public class SemaphorTest { // max 4 people static Semaphore semaphore = new Semaphore(4); static class ATMThread extends Thread { String name = ""; public ATMThread(String name) { this.name = name; } public void run() { try { System.out.println(name + " acquiring lock..."); Syste...

Microservices Architecture with Spring Boot in 15mins

Image
1. Introduction Microservices is not a new term. It coined in 2005 by Dr Peter Rodgers then called micro web services based on SOAP. It became more popular since 2010. Micoservices allows us to break our large system into number of independent collaborating processes. Lets see below microservices architecture. 1.1 What is Microservices Architecture? Microservices architecture allows to avoid monolith application for large system. It provide loose coupling between collaborating processes which running independently in different environments with tight cohesion. So lets discuss it by an example as below. For example imagine an online shop with separate microservices for user-accounts, product-catalog order-processing and shopping carts. So these components are inevitably important for such a large online shopping portal. For online shopping system we could use following architectures. 1.2 Shopping system without Microservices (Monolith architecture) In this architecture we are ...