Skip to main content

Posts

Showing posts from April, 2017

Understanding Concurrency, Threading and Synchronization

Thread: A thread is defined at the operating system level. It is a single execution of a program. A thread is a set of instruction. An application can be composed of several threads. Different threads can be executed at the same time. The JVM works with several threads like Garbage collector, JIT etc. What does mean by "At the same time"? In a single core of CPU, the threads cannot works at the same time, it give us a feel that it is running at same but in reality it work one by one and the context switch happen very fast in milliseconds which we can't observe. On a multi-core CPU, things happens at the same time. A challenge while this is the read and write operation involve while running different thread at same time. Who is responsible for the CPU sharing? There is a special element who does this, is called scheduler.there are three reasons for a scheduled to pause a thread -  The CPU should be shared equally among threads. The thread might be waiting ...

ClassNotFoundException and NoClassDefFoundError in Java

As the name suggest ClassNotFoundException is of Exception type and the NoClassDefFoundError is a type of Error. ClassNotFoundException can be handled inside code while NoClassDefFoundError can't. ClassNotFoundException and NoClassDefFoundError occur when the particular required class is not found during run-time. It occurs in different scenarios. ClassNotFoundException thrown when an application tries to load in a class through its string name using: The forName method in class Class. The findSystemClass method in class ClassLoader . The loadClass method in class ClassLoader. but not available during run time. For example, you might have come across this exception when you would have tried to connect to MySQL or Oracle databases and you have not updated the classpath with required JAR files. Most of the time, this exception occurs when you try to run an application without updating the classpath with required JAR files. For example, the below program will throw ClassN...

Basic Unix Commands quick reference

This quick reference lists commands, including a syntax diagram and brief description. […] indicates an optional part of the command. For more detail, use: man command 1. Files 1.1. Filename Substitution Wild Cards                ? * Character Class (c is any single character) [c…] Range                 [c-c] Home Directory         ~ Home Directory of Another User ~user List Files in Current Directory ls [-l] List Hidden Files                 ls -[l]a 1.2. File Manipulation Display File Contents         cat filename Copy                 cp source destination Move (Rename)         mv oldname newname Remove (Delete)         rm filename 1.3. File Pr...

StackOverFlowError and OutOfMemoryError in java

There are two area inside java virtual machine's memory the heap and the  stack . The  stack  memory is used to store local variables and function call while heap memory is used to store objects in  Java The most common cause of StackOverFlowError is too deep or infinite recursion or many local objects / variables creation inside function call in  Java.  According to the java source documentation,  Java throws  java.lang.StackOverflowError   when a stack overflow occurs because an application recurses too deeply. JVM has a given memory allocation for each stack of each thread, and if an attempt to call a method happens to fill this memory, JVM throws an error. Just like it would do if we try to write at index N of an array of length N.  The point to be noted here is that - These are errors not an exceptions. No memory corruption happens due to the error. Stack can not write into the heap space. A StackOverflowError i...

Semaphore in java

A  Semaphore  is a thread synchronization mechanism that can be used - To send signals between threads To guard a critical section for enforcing limited access to the resource Semaphore in java come with java 1.5 and available under package "java.util.concurrent"  Below is an example which you can go through to understand how we can enforce a limited number of thread to access a particular section of code at a time. import java.util.concurrent.Semaphore; public class SemaphoreExample { Semaphore semaphore = new Semaphore(2); private void printLock() { try { semaphore.acquire(); System.out.println("Lock acquired by "+Thread.currentThread().getName()); System.out.println("Locks remaining "+semaphore.availablePermits()); Thread.sleep(5000); } catch (InterruptedException ie) { ie.printStackTrace(); } finally { semaphore.release(); System.out.println("Locks release "+Thread.cur...

5 Important things to keep in mind for PPF and EPF

EPF deduction from salary comes under 80c section and there are limit of 1.5 lacks that you can show under 80c section and save tax. Most of the salaried employee invest in PPF account. These are the most important point we should keep in mind for better returns. 1) if you are thinking to invest lumpsum amount in PPF, try to invest in as early as possible after the start of new financial year. This will help you in getting rid of last moment hurdle and fetch more return. 2) Do invest before or by 5th of every month. Interest calculation happens for the month on the amount available on 5th of every months. In this case you will get interest for the month. If you deposit after 5th, you will loose interest for the remaining days of that month and interest calculation will only happen after next month on the deposited amount. 3) If you don't have UAN number for EPF account, ask employer and get it. 4) Once you have UAN number, go to EPFO website and activate it. 5) Ad...

Term plan vs Endowment plan insurance

Most people have in dilemma while deciding the insurance plan. It is bit confusing which one to choose. We need to know first what are these plans and what are their features. We can understand these with below one line description- Term plan = Pure insurance plan Endowment plan = investment + insurance Both have their advantages and disadvantage over one. 1) Premium and coverage: term plan have lesser premium than endowment plan and life cover amount is also too more than endowment plan. Endowment plan's premium cost more and it have lesser life coverage amount. 2) Maturity Benefit: The only benefit of endowment plan is that you get a certain guaranteed amount at the time of maturity that is why it is kind of investment. You will not get any maturity amount in case of term plan insurance but in case of unfortunate demise of insurgents, nominees will get a large amount cover. Most people prefer term insurance plan over endowment plan. One can save and invest the remaini...

HUFFMAN TREE - Notes

Job Sequencing with Deadlines

Given a set of n jobs Each job i has an integer deadlines di>=0 and a profit pi>0 All jobs requires only one unit time to complete Only one machine is available for processing jobs For job i the profit pi is earned if the job is completed by its deadline.

Investing in Mutual Fund - Direct Buy option

You want to invest in mutual fund but confused by seeing the different types of varieties for same fund? There are basically 2 types of mutual fund variance you can buy, one is direct and other is regular. Direct buy option doesn't involve adviser the expense ratio is less for direct option. Another is through adviser. Before buying your PAN must be kyc compliant. You can get e-kyc done from different AMC sites or even mutual fund websites. There are option available to get your e-kyc from sitting from home which uses your video to have the IPV done. once you are done with kyc, you can log-on to mutual fund website by creating your account with all the details required and start investing and will be able purchase the direct option. Now a days there are different sites came up with the option which provides you an aggreegated view to purchase directly from mutual fund houses. example - zerodha coin , invezta etc. Happy investing!!! Start you mutual fund investment online....

Issue in booting windows 10 after installation of ubuntu - Fixed

I installed 'ubuntu-16.04.2-desktop-amd64.iso' in my laptop along with windows 10. Installation goes well and after reboot, both Ubuntu and windows option was showing for boot. I was able to boot up Ubuntu and it was working fine as expected. While selecting the windows option to boot, it didn't boot and returning back to the boot selection menu. I was scared if the windows boot is corrupted or during installation if the drive got formatted or corrupted. I did some grub command but even after changing from grub command i was not able to fix the windows boot issue. i tried grub update but it didn't fix the issue. After lot of research on web i came to know the cause of the issue - 'grub.cfg'  file was not proper, to fix i followed the below - 1) login to Ubuntu OS 2) GO to /boot/grub/grub.cfg file 3) Edit the below section and add the missing line (ntldr /bootmgr) #### BEGIN /etc/grub.d/30_os_prober #### --- ---- --- chainloader +1 ntldr /bootmgr ...