Is public synchronized void run() a bad idea?
I have a class that extends Thread that downloads files. I want to ensure
that only one download is occurring at once, so I have a static reference
to the class, and check to see if it is null before creating a new
reference. However occasionally I notice that another instance of this
class is created, and therefore downloading on a different thread. I'm
trying to figure out what could cause this, however, would it be a bad
idea in general to mark the run() method of the Thread to synchronized (or
the method that calls start()) ? Are there any side effects to be aware
of?
No comments:
Post a Comment