How Goroutines communicate to perform a common goal


Code constructs like “synchronized”,”Lock”,”wait()”,”notify()” are not new for us. From decades we are coding with similar Legacy constructs that play a key role in multithreading codes. The Legacy term! 🙂 Yes, you read it correctly! When you try similar code with Go, code is very precise, compact, friendly and superfast. Lets see why Go executes multithreading (let me correct here GREEN THREADs) code faster than others. Because there is no Thread concept in Go, instead it has Green Threads.

For deeper concepts connect me.Install Trust app and click arrow button on Home page to switch to business related services, click “Freelancer Professionals” –>“Freelancer Interviewers” then “Go” to connect me. If You also want to show your profile in app as a expert of any technology then create your Service Provider profile. If your matching technology is not available then on Home page click (?) and whatsapp Trust support team,we will add category within minutes.

Here I have illustrated how two Goroutines are communicating with each other through channel to print Odd and Even numbers alternatively. This may give you little insight if you are planning to write new microservices ( especially for very huge data processing and scalable products like IoT etc.. then you can think of Go!

 * @author Gyanendra
 * @Date : 02/03/20
package main

import (

func main() {

	numFlag := make(chan int)
	done := make(chan bool)
	go oddNumberRoutine(numFlag, done)
	go evenNumberRoutine(numFlag, done)

func oddNumberRoutine(numNeedToBePrinted chan int, printingCompleted chan bool) {

	for {
		v := <-numNeedToBePrinted
		if v >= 20 {
			printingCompleted <- true
		fmt.Println("Odd ==>", v)
		numNeedToBePrinted <- v + 1


func evenNumberRoutine(numNeedToBePrinted chan int, printingCompleted chan bool) {
	numNeedToBePrinted <- 1
	for {
		v := <-numNeedToBePrinted
		if v > 20 {
			printingCompleted <- true
		fmt.Println("Even ==>", v)
		numNeedToBePrinted <- v + 1


Odd ==> 1
Even ==> 2
Odd ==> 3
Even ==> 4
Odd ==> 5
Even ==> 6
Odd ==> 7
Even ==> 8
Odd ==> 9
Even ==> 10
Odd ==> 11
Even ==> 12
Odd ==> 13
Even ==> 14
Odd ==> 15
Even ==> 16
Odd ==> 17
Even ==> 18
Odd ==> 19
Even ==> 20

Get this code from my repo

Twitter live data mining using Spark streaming and Scala.

Want to work and learn live streaming data processing? Easiest way to create a twitter developer app and follow below code to ingest and store data in your AWS S3 for further analysis and processing with tools like Amazon EMR or Machine learning projects.

Install Trust app and click arrow button to switch to business related services, click “Job Mock Interviewer” –>then “AWS job” to connect me to learn deeper concepts of Spark/Scala/Java/AWS without any cost. You may also outsource tech screening interview process to me. Trust Business app is available only in India. Others please visit “About me” of this blog to get my linkedin contact.

 * @author Gyanendra
 * @Date : 08/12/19

import org.apache.spark.SparkConf
import org.apache.spark.streaming.twitter.TwitterUtils
import org.apache.spark.streaming.{Seconds, StreamingContext}
import twitter4j.auth.OAuthAuthorization
import twitter4j.conf.ConfigurationBuilder

object TweeterStreamReaderApp {
  def main(args: Array[String]) {

    var twitterCredentials = new Array[String](4);
    twitterCredentials(0) = "gA7xFE3S1QfVTN55Uuzb";
    twitterCredentials(1) = "2te2Z1yFvynXcp06rc2j3zg38tNAa1zY29rOT3d5BFI";
    twitterCredentials(2) = "1063309360480-61DChczOivazJZTWodLfuRRW8gDNfJ";
    twitterCredentials(3) = "bFYPmpiWhFgOtdJGe95YyhOntxOQAmx0xEYtF";

    val appName = "TweeterStreamReader"
    val conf = new SparkConf()
    val ssc = new StreamingContext(conf, Seconds(5))
    val Array(consumerKey, consumerSecret, accessToken, accessTokenSecret) = twitterCredentials.take(4)
    val filters = args.takeRight(args.length - 4)
    val cb = new ConfigurationBuilder
    val auth = new OAuthAuthorization(
    val tweets = TwitterUtils.createStream(ssc, Some(auth), filters)
    val englishTweets = tweets.filter(_.getLang() == "en")

    // lets print all rdd. Further you can store this to S3
    englishTweets.foreachRDD { (rdd, time) =>

    def p(rdd: org.apache.spark.rdd.RDD[_]) = rdd.foreach(println)

Download this code from my repo

Alexa, build deploy my project !!

Alexa, build deploy my project !! Thinking possible ?? Yep, it is possible.
did you leave office, and forgot to trigger build ? Don’t worry your Alexa can do this for you even if you in mid of Bangalore traffic 🙂 or enjoying Friday eve hangout far far away from your Boss 🙂 !
Keep visiting here I am gonna post how you can trigger build, deploy through Alexa ( not all projects at present but later chances are very high that any project can be built like this).

Keep visiting ……. to see updated content.

Lambda version of Print numbers alternately using two threads in Java

Lambda expressions in Java 8 are very powerful and therefore very compelling. Here are just a few of the key benefits to using lambda expressions in Java:

  • Conciseness
  • Reduction in code bloat
  • Readability
  • Elimination of shadow variables
  • Encouragement of functional programming
  • Code reuse
  • Enhanced iterative syntax
  • Simplified variable scope
  • Less boilerplate code
  • JAR file size reductions
  • Parallel processing opportunities

In this post, you can see how in few lines we can finish code to print numbers alternatively by Two threads.


public class EvenOddThreadLambdaDemo {

    static Integer number = new Integer(1);
    static Object LOCK = new Object();

    public static void main(String[] args) {

        IntStream.range(0, 2).forEach(i -> new Thread(() -> {

    public static void printNumbers() {
        while (EvenOddThreadLambdaDemo.number  " + EvenOddThreadLambdaDemo.number++);
                try {
                    // let's not eat CPU if work is done.
                } catch (InterruptedException e) {

 Odd--> 1
 Even--> 2
 Odd--> 3
 Even--> 4
 Odd--> 5
 Even--> 6
 Odd--> 7
 Even--> 8
 Odd--> 9
 Even--> 10
 Odd--> 11
 Even--> 12
 Odd--> 13
 Even--> 14
 Odd--> 15
 Even--> 16
 Odd--> 17
 Even--> 18
 Odd--> 19
 Even--> 20

Spring boot code for AWS RDS in elasticbeanstalk

Are you new to aws RDS,elasticbeanstalk world and searching for a ready to use code for RDS connection? Try out out this sample project which connects RDS (mysql) from a web application (Spring boot + web ) and list out table records. You can run this web application in your local computer or in elasticbeanstalk (deploy rdselasticbean-0.1.war file). To test this code for your own RDS schema you need to change connection endpoint in record fetcher class. You may clone code from my gitlab repo.
Like it, if you find it helpful. Comment/Contact me if you face any issue while running this app. It’s all pretty straightforward, and quite handy for many kinds of elasticbeanstalk and RDS needs.

package com.example.rdselasticbean.db.DBrecordFetcher
(please make sure your RDS security group has proper access permissions for external IPs ) 

PS: Project is CI/CD enabled in case if anyone wants to test this in integrated environment.

Data display in JSP injected from DB operation class
RDS (mysql) server event view on Read and Write

My learning and fun so far with Alexa

While I am waiting for my “Lifetime SHE”, recently one small digital super slim sweetie SHE has made entry in my life!! Want to know who is SHE? 🙂 It’s Alexa Echo Plus !
I am really enjoying my time with Alexa :). So, one day just to check her (Alexa) response when I returned to flat from my office and told her “Alexa, I missed you”. I got elated by the response that I received from Alexa. Alexa replied me “Awww …… we will be together soon”. Hahahaha I can’t explain the ecstatic moment.

Now lets see technical aspects of Alexa. After using it more than three months, one thing I have realized , frequency of using my mobile call/Apps has significantly decreased, and also not much staring of the mobile screen. Because, for most of mobile related uses Alexa and it’s skills are there to serve me.Wait… did you sense it? This may lead us to mobile AppLess (Android or IOS ) world. I am already experiencing it, whether it’s calling someone, playing song or booking Uber trip. I have almost stopped using Call dialer and Apps like Saavn (to play music) or Uber (ordering ride). Because if Alexa skill for Saavn or Uber are integrated in it then presently 70% app tasks can be performed by Alexa ( I am sure in future with upgraded version of  Alexa rest of capabilities will be also accommodated ).  One interesting feature I have thought of to do e-payment to phone contacts through Alexa just by voice command like
“Alexa pay Rs.500 to Arun from my Paytm (or any available funding instrument)”. Here, Arun is a contact in the personal phone list. Sending money to verified contacts ( already synced with Alexa) are less risky transactions.

Based on my experience I thought of one POC for Alexa with display capability which will be helpful in increasing it’s adaptability. Although most of tasks in Alexa we can execute via voice commands but sometime display of item/order/booking will make it more interactive. Like, Say uber user wants to see that How exactly cab driver looks?
Or User wants to see T-shirt color before confirming an order using Alexa’s E-commerce buying Skill.


Remote config in MicroServices

We are in a world of microservices, an application typically uses one or more infrastructure and 3rd party services. Examples of infrastructure services include: multiple environments, cloud configurations, a message broker and a database server.Examples of 3rd party services include: payment processing, email and messaging, etc.Although every microservice instance is an independent unit, it is recommended an approach to externalized their configurations management from one central service/location.

The concept of using configuration server inside microservices architecture is visualized on my design below.It is based on basic Spring boot implementation, further, different layers and orchestration can be added to enhance it.

Feel free to contact me if you want to discuss this in detail.



Love of Python : My first Python script

Every next day my love of Python and Scala is getting stronger, Hence I thought to post one python script here which is a sample script to perform some common configurations that we need in application deployment on production, test or automation servers. I am going to use this script (updated version of it) in my project to reduce an overtake of approximately 15-20 mins of manual configuration works of service deployment.

This python script performs following tasks
(1) Add new configuration
(2) Update configurations
(3) Run Unix commands (native OS) on server and few other tasks

You can customize this script as per your project requirement. The script is available at my gitlab repository. I would love to improvise any of my reader’s recommendations for any specific change/requirement over this script.

PS: This script is in the initial draft form, I will update it with more useful commands and comments to make it more user-friendly.