I currently wrote my program to use 32 threads and read 1 file per thread (so 32 .txt files). The multi-threading has nothing to do with CPU speed, but making 32 calls to BING's api per second is a lot faster than making 1. Each of the .txt files containing a list of search queries. I create a thread it reads one line at a time from it's file. Is it possible to create all 32 threads and point them to a single .txt file??
Use the Producer-Consumer pattern. Have only one thread that reads file and pushes each line/command into ArrayBlockingQueue (thread safe read and write) using put().
All other 32 threads should read from the same queue object by calling take(). They will block if queue is empty, which is nice.
This solution is better because the disk is inherently single-threaded so you won't get much by reading the file concurrently.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With