Pros:
Makes use of multiple processors: Increasing the clock speed is more difficult and expensive than increasing the number of cores, so the trend is to increase the cores. To avail the benefits of multi-core your program should be multi-threaded.
Modularity : A big task task can divided logically and can be handled by separate thread synchronously. Though we dont get a performance improvement in this case as the threads are executing in sequence one after the other we are achiving a better modularity here which helps in debugging.
Handling async requests: A server application which is multi-threaded – one thread for each requests – with synchrous I/O is easier to develop and less error prone than a single threaded application with asyncrhous I/O.
Better UI responses : The progress bar, pop-up messages, alerts, doing multiple operations etc. are not possible with a single threaded UI.
Cons/Risks:
Safety issues: Without proper synchronization a program where the order of execution is important can cause unexpected results with multiple threads. This is because multiple threads sharing the same memory allocated to the process.
Liveness issues: Deadlock, starvation & livelock are the culprits for multi-threaded programs to enter into non-live state.
Performance issues: Through one of the main reason for multi-threading is performance improvement, the switching and scheduling of threads introduces a slight performance impact. So in rare cases when this performance overload is more than executing the program in single thread prefer single-thread.
Reference: Java Concurrency in Action
I don’t commonly comment but I gotta state thankyou for the post on this amazing one : D.
LikeLike