JVM Garbage Collection and Optimizations

Overview When troubleshooting systems for performance-related issues, memory optimizations are a place that needs a deep analysis of what each system stores in the memory, how long those are stored, and access patterns. This post is to keep a note on the background information and valuable points to note in such an effort, specific to Java-based implementations as a deep understanding of the JVM behaviors is very beneficial in the process.

Java language provides much convenience to the developers by taking care of the memory management to a great extent letting the focus be on the rest of the logic. Still having a good understanding of how Java does this underneath, rationalize several best practices we follow in Java implementations and help design the programs better and think seriously on some aspects that can later lead to memory leaks and system stability in the long run. Java Garbage Collector has a big role in this been responsible for freeing up memory by removing memory gar…

How to Pick Best Stocks in Share Market

When thinking about investments, 3 things come to my mind, in the Sri Lankan context.
  1. Buy real state in a suburb or a town that is fast growing
  2. Put in a Fixed Deposit in a bank
  3. Invest in the stock market
As the current FD rates are in the declining phase, it did not really come as a good option for me at the moment of writing this. Hence I thought to investigate a bit on investing in the share market as it doesn't really need a larger amount of money as to by property as in option 1.

Below is an insightful speech by the richest person in Sri Lanka, who is known as a business magnate, 'Mr. Dhammika Perera', explaining how he started with share market (while the overall speech highlights many important facts, he specifically talks about share market from 6minutes and 26 seconds. Speech is in Sinhalese).

One thing he said, captured me that do not enter a business if you do not know about it. He also emphasized that it's the knowledge we should seek, not money, which surprised me to hear from him until I understand the depth of that statement.

Why you should not totally depend on your stock broker's advice?

As pointed out in Mr.Dhammika Perera's speech, if stock broker's adviser is so brilliant first they would have made their own investments and be rich than keep doing a job that ends up in a monthly salary. That is one aspect to look at it. While I really value the adviser's inputs as he is much more experienced in the business while I am a novice, still it doesn't stop me from learning the art and analyze why he is saying it. 

Also, there are stock market manipulations such as 'Front running' where stockbrokers use their advance knowledge of pending customer orders to make a profit. Nowadays, since investors can directly place an order online, I suppose this is under some control. 

Ultimately no one else out there will have a need to earn for you than you yourself.

How to select stocks to buy?

I am just suggesting this with my 3 months knowledge gathered investigating the share market businesses. Therefore take it at your own risk or comment if you know better. :)

1. Price going up or down?

Obviously, we buy when the price is low and we sell when the price is high. The difference will make our profit after deducting broker fees and other commissions, or make a loss if hard luck. So the question is how to judge whether it's low price or a high price or where the prices will go in the future. This may look simple at a glance, but this is the most complex decision to take in a stock market. Sometime price may be in a decreasing trend, yet not really at a low range.

To help make a decision amongst this complexity there is a technical methodology that needs to be mastered. In this technical analysis, it analyzes the past data statistically identify some known patterns that have proven to work with a good probability. Here it tries to apply these known patterns to the past data of a particular stock. It will need some experience to train your eye to see these patterns in the candle charts, but mastering it will be a great support in the decisions. Below is such analysis done on Sampath Bank stocks.

Once the patterns are identified there are 3 more statistically calculated indicators that can be used to further refine and time the purchase or sale.
  • RSI - Relative Strength Index 

 This indicates the speed and change of price movements of a specific stock. This can be a value from 0-100, where values below 30 indicate oversold --> time to buy and values above 70 indicates overbought --> time to sell.
  • Stochastic RSI (STOCH RSI)

Here the limits to consider are 20 and 80 in contrast to RSI. While I am still trying to understand the different theories behind this and RSI, the rule of thumb is to depend on RSI in a trending market(going in one direction, up or down) while weighting STOCH RSI more in a choppy market(going both up and down). This is not recommended to use as the sole indicator without combining with others.
  • MACD - Moving Average Convergence Divergence

This is a trend following indicator. This link(https://www.investopedia.com/terms/m/macd.asp) provides more insight on how to read it properly.

MACD is a lagging indicator that can reveal information on strength, momentum, direction, and duration of a trend. Zero crossover, Divergence is most important to look at.

Below is a candle with the above indicators shown at the bottom. Making use of what they are trying to tell us is in our hands with experience and knowledge we gain.

2. Is the price is above the net assets value of the company? 

Next thing that needs to be considered apart from the above indicators is whether the share price within the net asset value of a company. It is not rational to buy shares above the net asset value of a company in most of the cases.

3. Dividends

Dividends is another we can make profits. There are several companies in the Sri Lankan stock market, which has continuously paid dividends to their investors, at their financial year or as interim dividends. Within this set of companies, there are few dividends paying companies that are released from taxes as well. We should also consider this as a plus point at buying and should check if there is a dividend announcement and pay attention to XD-date. Following 2 dates are significant in receiving dividends.

Record date - This is the date when we must be on the company records as a shareholder to receive the dividend.

XD-date (Ex-Dividend Date) - If we purchase a stock on its XD date or after, we are not eligible to receive the dividend payment. Instead, the seller gets the dividend. If we purchase before the ex-dividend date, we get the dividend.

4. General Knowledge

Then additionally we can make use of general information like recent political changes, tax enforcement, laws, consumer trends, new innovations, foreign impacts etc. to predict on the future of market segments to make the investment decisions more accurate.

Some useful resources:

Cheers! Happy investing.. (Feel free to add any tips you like to share.)


  1. This comment has been removed by a blog administrator.

  2. Thanks for sharing the wonderful and helpful information
    Delhi Agra Jaipur Yatra
    India Trip Designer


Post a Comment

Popular posts from this blog

Signing SOAP Messages - Generation of Enveloped XML Signatures

OPA for HTTP Authorization

How to Write a Custom User Store Manager - WSO2 Identity Server 4.5.0