简体   繁体   中英

Correct approach to multi-threading

I have recently pondered on the general approach to multi-threaded code that would be most efficient. As with concurrent collections atomic mechanisms such as Compare-And-Swap are used to provide efficient implementation of collections such as queues. I was wondering whether there are any new approaches to writing multi-threaded code, for instance in java, rather than using pure Thread instances? Are thread pools used more often perhaps?

There are few new approaches emerging:

  • message passing and actor-model, see (well, the idea comes from ...)

  • - massive multithreading with thousands of simple micro-threads

  • transactional memory (see: )

I am sorry to blindly point you to the Concurrent API , but if you work off of that you may not need to use some of the lower level concurrency controls. That really should be decided on what ever best fits your applications needs/design.

Take a look at the ExecutorService and the ForkJoinPool classes. Both make it much simpler to manage/maintain thread pools.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM