Sum up - Java Thread Interview Questions (Updating)
2016-02-06 12:18
405 查看
Java Thread Interview Questions
1. Difference between Thread and Process in Java?
Thread is subset of Process, in other words one processcan contain multiple threads. Two process runs on different memory space, butall threads share same memory space. Don't confuse this with stack
memory,which is different for different thread and used to store local data to thatthread.
2. When to use runnable vs. Thread
Thisis follow-up of previous multi-threading interview question. As we know we canimplement thread either by extending Thread class or implementing Runnableinterface, question arise, which one is better and when to use one? Thisquestion will be easy to answer,
if you know that Java programming languagedoesn't support multiple inheritance of class, but it allows you to implementmultiple interface. Which means, its better to implement Runnable than extendsThread, if you also want to extend another class.
3. What is race condition inJava?
Racecondition are cause of some subtle programming bugs when Java programs areexposed to concurrent execution environment. As name suggests, race conditionoccurs due to race between multiple threads, if a thread which is supposed toexecute first lost the
race and executed second, behaviour of code changes,which surface as non-deterministic bugs. This is one of the hardest bugs tofind and re-produce because of random nature of racing between threads.
4. Share data between threads: You can share data betweenthreads by using shared object, or concurrent data-structure likeBlockingQueue.
5. ThreadLocal variable: ThreadLocal variables are specialkind of variable available to Java programmer. Just like instance variable isper instance, ThreadLocal variable is per thread.
6. Difference between synchronized and concurrent: Thoughboth synchronized and concurrent collection provides thread-safe collectionsuitable for multi-threaded and concurrent access, later is more scalable thanformer.
To be continued...
1. Difference between Thread and Process in Java?
Thread is subset of Process, in other words one processcan contain multiple threads. Two process runs on different memory space, butall threads share same memory space. Don't confuse this with stack
memory,which is different for different thread and used to store local data to thatthread.
2. When to use runnable vs. Thread
Thisis follow-up of previous multi-threading interview question. As we know we canimplement thread either by extending Thread class or implementing Runnableinterface, question arise, which one is better and when to use one? Thisquestion will be easy to answer,
if you know that Java programming languagedoesn't support multiple inheritance of class, but it allows you to implementmultiple interface. Which means, its better to implement Runnable than extendsThread, if you also want to extend another class.
3. What is race condition inJava?
Racecondition are cause of some subtle programming bugs when Java programs areexposed to concurrent execution environment. As name suggests, race conditionoccurs due to race between multiple threads, if a thread which is supposed toexecute first lost the
race and executed second, behaviour of code changes,which surface as non-deterministic bugs. This is one of the hardest bugs tofind and re-produce because of random nature of racing between threads.
4. Share data between threads: You can share data betweenthreads by using shared object, or concurrent data-structure likeBlockingQueue.
5. ThreadLocal variable: ThreadLocal variables are specialkind of variable available to Java programmer. Just like instance variable isper instance, ThreadLocal variable is per thread.
6. Difference between synchronized and concurrent: Thoughboth synchronized and concurrent collection provides thread-safe collectionsuitable for multi-threaded and concurrent access, later is more scalable thanformer.
To be continued...
相关文章推荐
- UITableViewCell上左滑删除
- N-Queens 题解
- N-Queens II 经典问题:8皇后问题 题解
- 自定义可以响应事件的控件(继承自UIControl)
- Circuit Breaker Pattern(断路器模式)
- hdoj1423Greatest Common Increasing Subsequence【LCIS】
- Android关闭所有系统的UI控件
- 【HDOJ】3686 Traffic Real Time Query System
- junit4X系列--Builder、Request与JUnitCore
- junit4X系列--Builder、Request与JUnitCore
- GPU的deviceQuery 和 Nvidia-smi的使用
- HDU 1005.Number Sequence【用递归会超时】(2.5)
- 运行MIT-GNU Scheme出现“Requested allocation is too large”
- UITableView全面解析
- Java之serialVersionUID
- Leetcode 动态规划 Unique Paths
- easyui textbox添加blur事件
- String、StringBuffer和StringBuilder的深入解析
- Cross-Platform GUI:2D/3D Graphics, Networking, IDE
- Android组件及UI框架大全