I am about to write my first multi threaded Java application. The task basically is to create sales report for a set of products; the products and the inputs to the report generator class are completely independent.
I believe we can create multiple threads (I would like to control the number of threads to create from a properties files based on number of CPUs in the target machine). to use them generate reports asynchronously. Currently this is what I do in my single threaded program.
I wish Java gurus give me some inputs on the design. Thanks in advance.
Structure of Report Generator class
My current implementation which I would like to perform in a multi threaded approach.
I would like to know what is the best way to first create a set of threads and make them pick a product and generate report.
Firstly you’ll want to create a class the implements the interface Runnable. Your new object that implements the interface Runnable could take the ArrayList of products, then in the implemented method run() you could create a new instance of SalesReportGenerator and start generating your report.
So for each time a request comes in for a report you create a new thread passing in via the constructor an instance of your new object that implements Runnable and then start the thread.
This is the basics but with this and a little research on Threads you should be able to get this going.