What is the Difference Between Processes and Threads

A process is an execution of a program but a thread is a single execution sequence within the process. A process can contain multiple threads. A thread is sometimes called a lightweight process.   A JVM runs in a single process and threads in a JVM share the heap belonging to that process. That is why several threads may … Read more

Can we Synchronize the Constructor of a Java Class

As per Java Language Specification, constructors cannot be synchronized because other threads cannot see the object being created before the thread creating it has finished it. There is no practical need of a Java Objects constructor to be synchronized, since it would lock the object being constructed, which is normally not available to other threads … Read more

Can we Synchronize the Run Method? If yes then what will be the Behavior

Yes, the run method of a runnable class can be synchronized. If you make run method synchronized then the lock on runnable object will be occupied before executing the run method. In case we start multiple threads using the same runnable object in the constructor of the Thread then it would work. But until the … Read more

What is Thread Pool? Why should we use Thread Pools

A thread pool is a collection of threads on which task can be scheduled. Instead of creating a new thread for each task, you can have one of the threads from the thread pool pulled out of the pool and assigned to the task. When the thread is finished with the task, it adds itself … Read more

How can I Trace whether the Application has a Thread Leak

If an application has thread leak then with time it will have too many unused threads. Try to find out what type of threads is leaking out. This can be done using following ways: Give unique and descriptive names to the threads created in application. – Add log entry in all thread at various entry … Read more