Tag: java multithreading interview question
-
Difference between Runnable and Callable
Both Runnable and Callable interface are used to encapsulate task supposed to be executed by another thread. Runnable and Callable both run on a different thread than the calling thread. There are certain things which Runnable can not do like throwing checked exception and returning result after computation. Java team could have changed the signature…
-
How can you access the current thread in Java?
Sometimes we need to know about the currently executing thread. For example, for debugging purposes we want information about current Thread. Current thread here means the currently executing thread object in Java. currentThread() method returns a reference to the currently executing thread object. In the following example, currently executing thread is ‘main’ thread. We can get the…
-
What is Thread in Java?
Thread is a lightweight process. Threads exist within a process. So every process has at least one thread. Thread in Java is represented by java.lang.Thread class. Every Java application has one or several threads. There are two ways to create thread in Java:
