T
Tim Smith
I've seen quite a few examples where main() pretty much just makes an
instance of some class, and then creates a thread and sets the thread to
running the run() method of the aforementioned class, and then main is
done. The only thing of substance in the aforementioned class is the
run() method, which does some kind of loop acquiring work to do. When
it acquires work, it makes an instance of some second class, which
actually does the work.
Is there actually a good reason to have a class whose sole function is
to run a loop in a thread, as opposed to just running that loop in
main()?
For example, a network server might have a class that just loops in a
thread, accepting connections on a listening socket, and then
instantiating some processing class for each accepted connection.
Why not just have main() create the listening socket, and then loop
accepting connections, doling them out to new instances of a processing
class?
instance of some class, and then creates a thread and sets the thread to
running the run() method of the aforementioned class, and then main is
done. The only thing of substance in the aforementioned class is the
run() method, which does some kind of loop acquiring work to do. When
it acquires work, it makes an instance of some second class, which
actually does the work.
Is there actually a good reason to have a class whose sole function is
to run a loop in a thread, as opposed to just running that loop in
main()?
For example, a network server might have a class that just loops in a
thread, accepting connections on a listening socket, and then
instantiating some processing class for each accepted connection.
Why not just have main() create the listening socket, and then loop
accepting connections, doling them out to new instances of a processing
class?