Using Channels with threads for a data pipeline


#1

I’m a kotlin newbie using channels to implement a data pipeline. for higher throughput of data i need threads. i’ve implemented it the following way:

first i’m creating threads

 val threads = Array(workers) {
        newSingleThreadContext("worker-${it}")
    }

then I assign them

 val consumer = Array(workers) {
         produce(threads[it]) {
             println("${Thread.currentThread().name} Start Consumer")
             ...
             send("finished")
        }
    }

So I’m asking, is this a ok? is there a better way to do it?

Thanks!


#2

Can you avoid to use a dedicated thread pool?
Are you considered built-in dispatchers?


#3

Well the question is, can i avoid a dedicated thread pool, if i want max throughput? which built in dispatchers could i use as alternative? thx!


#4

Yes, you can.
See dispatchers documentation for further details.