I have done a Download manager that works just fine. I need to re-write just a tiny bit of it with a monitor (multi-thread) It is not so much work but I cant get it to work proberlyI need this:
I got all the code for a running app and need to rewrite so it works with the multi-thread(notify, wait)
The Downloader class
This class inherits from Thread and, of course, has a run()-method where all its work is done. As it is supposed to download a networked file, it will need a URL. The controller will notify each thread when the URL is written to disk. This means the Downloader class constructor must have a parameter that is a reference to a Controller object (a method in the Controller class is called from each Downloader instance). When notified that there is a URL available, a Downloader should read that URL from a file (with a fixed name, in a fixed place (preferably in the working directory)), delete the file and then proceed to download the networked file to disk (preferably to the working directory). This means that each thread in its run() method should call the Controllers getURL() method (see below).
The Controller class
This class plays the role of monitor. There should be a method in this class called getURL() that will be called by the individual threads. This means that this method should be synchronized and use wait() and notify() calls. There should also be a boolean in this class, indicating whether there is a URL-file for consumption. This boolean will be used by the main() method (see below). When the Controller has notified a Downloader that there is a URL file to be consumed, the boolean should be reset (false).