Posts

Showing posts from 2018

Integer Class possible NullPointerException

While I was debugging, I got NPE which is not happy. When I glanced at the codes, it seemed that there was no problem. But after looking through line by line, I finally got the point. For example, let's have a class Result. public class Result { private Integer rcode ; public Integer getRcode () { return rcode ; } public void setRcode ( int rcode) { this . rcode = rcode ; } } It has only one Integer variable. If the class is instanciated from json or without validation, rcode could not be initialized and could not have any value.  And at the point the value is compared, NPE comes. Result result = new Result() ; if (result.getRcode()== 1000 ){ // NPE happens! System. out .println( "this cannot be reached." ) ; } Same situation can happen if we take this variable as a method with primitive parameter. public static void printReturnCode ( int rcode){ System. out .println( "this also cannot b...

It's so hard to change.

Recently, I had two tests. One on online judge site and another one at work. In common after two tests, I realized that I had never designed any method at first time. Studying algorithm and architecture, I learnt that 1. problem define 2. simplify problem 3. design how to solve 4. design method 5. name a great name on methods and variables But when I faced a real test, I totally forgot what I learnt from study. Only thing that I did was reading the problem, starting the typing. On daily work, for sure, I have changed nothing. Get a mission and start to type. No consideration about other services, maintainability, optimization, and even test cases. Why I am not changed after reading and learning the quality of good software engineer. I think it has been long time with this habit and it's not easy to change at once. I think I need to keep thinking and trying to change every single day.

Add index on column for select performance to Mysql Database

Recently, I got a request from co-working department. They asked me to find rows using specific keys. Thank goodness, it was just a single table selection. The problem was that they need 50,000 specific records out of million records. More over, the department didn't have any information about the primary keys. They only know the specific data which is exactly mapping to the column on mysql table. So I decided to add index on the table. Before adding index, I tried on Mysql console to find out how long it will takes and what the result of describe query will be. About the table, select count(*) from table; ==> 1206240; SELECT     table_name AS `Table`,     round(((data_length + index_length) / 1024 / 1024), 2) `Size in MB` FROM information_schema.TABLES WHERE table_schema = "database"     AND table_name = "table"; ==> 292.30 MB Every value of the specific_column's length is 24. About the Server, Mysql Server : AWS RDS mysql 5.7....

How to deal with java.lang.OutOfMemoryError

First, when java.lang.OutOfMemoryError  error thrown? - when there is insufficient space to allocate an object in the Java heap - when there is insufficient native memory to support the loading of a Java class - when an excessive amount of time is being spent doing garbage collection and little memory is being freed Check, Was it thrown  - because the Java heap is full? - because the native heap is full?  Particularly, investigate right after the full GC happen. - Mainly, it's about allocation and reference. - Using profiler to check allocation and reference are on its purpose. - soft reference / weak reference Look into Code. - Estimate the size of memory needed in the application. - Evaluate how much you can reduce the amount of memory. - get the leak point. Rarely  - increase max heap size - scale-up/out  machine References -  https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/memleaks002.html - https:/...

Data migration on PRD

Sometimes, data should be migrated on PRD environment. Some kind of things should be considered before migration start. 1. How long does it take to complete the migration job? In PRD environment, user data is changing in real time. Suppose we have to move user's content. User can add or delete contents whenever they want. If all users upload new contents ( for example, their photos, videos ) and the size of new contents is always bigger than the size of the contents we can migrate, this migration never ends. 2. Users don't need to know the behind scene. As a customer, we don't want to see pop-up saying "Your data is migrating now.. so visit again later."  If it is possible, data migration process and user request handling process should be separated. For example, serve them with original data until migrated. After migration completed, route the user request to migrated service. 3. Integrity!!! The most important thing we must care about in migration...

Definite Sentences

Practice makes perfect. Later never comes. The moment learning and training end is the moment my career ends.

Being a software craftman step by step

Recently, I started to prepare for the next step of my career. As a software engineer, I think I need a blog to review and write about experience so that I can remember. It will be about  - things what I need to become a senior/better engineer - experienced issues from work - personal diaries I cannot become an expert at one day. Maybe I would be if I grow up step by step, day by day. To record and review this process, I start this blog.