Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is thread hopping and when is it necessary?

Saw the term 'thread-hopping' while reading some documentation, I didn't find a good description after a few minutes of googling. So as per title, what is thread hopping and when is it necessary?

Context - I came across the term while reading source code https://github.com/Netflix/RxJava/blob/78c250bf4429501db4e285a4840f0b934797d5a7/rxjava-core/src/main/java/rx/schedulers/ExecutorScheduler.java#L37

like image 886
Charles Ma Avatar asked Oct 31 '22 22:10

Charles Ma


1 Answers

I guess it is the phenomenon of having a lot of tasks/jobs/runnables being executed by an executor service which is backed by a pool of threads with unknown internal queueing mechanisms.

In such cases there might not be a way to predict which job is running in which of the pooled threads and special attention has to be paid to communication between threads, ownership, ..

In a way the execution of tasks hops from thread to thread. This is not strictly necessary, one could implement affinity to threads, but it's often difficult to avoid, so one has to be careful.

I got my knowledge about this from googling for some time. Therefore I make it community wiki.

like image 78
2 revs Avatar answered Nov 18 '22 07:11

2 revs