Sum up - Java Thread Interview Questions (Updating)

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...

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值