Sunday, June 25, 2017

Java Multithread Questions

1. What is the difference between Callable and Runnable?
    Runnable is Old and has been there for a while.
    People knows how to run at the beginning. Once she runs away, you don't get back from her.
    Callable can return a result and cannot throw a checked exception

2. How to detect deadlock in Java?
    Use ThreadMXBean class. It has a method called findDeadlockedThreads.

3. Difference between static variable and volatile variable in Multithread java
    Declaring a static variable in Java, means that there will be only one copy, no matter how many objects of the class are created. However, threads may have locally cached values of it.
    When a variable is volatile and not static, there will be one variable for each Object.

No comments:

Post a Comment