What is “non-blocking” concurrency and how is it different than normal concurrency?

前端 未结 8 1076
滥情空心
滥情空心 2021-01-30 02:26
  1. What is \"non-blocking\" concurrency and how is it different than normal concurrency using threads? Why don\'t we use non-blocking concurrency in all the scenarios where
8条回答
  •  误落风尘
    2021-01-30 02:57

    1) What is Non-blocking Concurrency and how is it different.

    A task (thread) is non-blocking when it doesn't cause other tasks (threads) to wait until the task is finished.

    2) I have heard that this is available in Java. Are there any particular scenarios we should use this feature

    Java supports at its own multithreading. You can take benefit of it to run multiple tasks concurrently. When well written and implemented, this may speed up the program when running at a machine with multiple logical CPU's. To start, there are java.lang.Runnable and java.lang.Thread as low level concurrency implementations. Then there is high level concurrency in flavor of the java.util.concurrent API.

    3) Is there a difference/advantage of using one of these methods for a collection. What are the trade offs

    I would use Collections#synchronizedList(), not only because that's more robust and convenient, but also because a Map isn't a List. There's no need to attempt to homegrow one when the API already offers the facility.


    That said, there's a Sun tutorial about Concurrency. I recommend you to get yourself through it.

提交回复
热议问题