Callable & Future in simple words

Sometimes we have to run a long-running task in a separate thread and return the result once execution is complete. Using Java Runnable interface we can run a task, but the disadvantage is it does not return result once execution is complete.

Then how can we achieve this?

There are two interfaces available in java.util.concurrent package using them we can solve this problem.

Continue reading “Callable & Future in simple words”

JAVA: Schedule Task in Java

Many times we have to write some set of task which can be executed after a certain interval of time. These types of task are called timer task.

So we can achieve it by using threads which will sleep for a certain amount of time and execute again. But wait, Can Java do this for me So that I can focus on logic instead of worrying about how to schedule tasks for me?

Yes, Java can do the scheduling thing for you. So you write your logic and let Java handle the scheduling work.

Continue reading “JAVA: Schedule Task in Java”

Java: Garbage Collection

When someone asks me “Tell me one thing you likes about java?” and my answer is short and simple “Garbage Collection” .

What is Garbage Collection:

 As JVM memory is limited, you need to remove unused objects, so your application have enough memory to perform it task. Garbage collection is the process of removing unused objects from heap memory.  

Continue reading “Java: Garbage Collection”