Java Reference
In-Depth Information
Figure 5-6. RuntimeException propagating to the top of the thread stack
Caution It is important to realize that the RuntimeException propagates to the top of the stack for the
thread it is running in, not for the entire JVM . As can be seen in Figure 5-6, even after the RuntimeException
has been thrown, and Thread-1 has died, the main thread is still operational. This has important ramifica-
tions when developing your server code—if you throw a RuntimeException and don't catch it, it is
possible that your server will still be running while being unable to process any requests.
The DvdDatabase Class: A Façade
Before building any class, it is worthwhile considering what it is that the class does. The same
applies to methods—for each method, try to determine just what the method does. If you find
yourself using the word “and” when describing a class or method, there is the possibility that
the class or method is trying to be responsible for more than it should. You might then con-
sider whether it makes sense to break a class or method into two or more classes or methods;
it might make your code a bit more manageable and maintainable.
In the case of our DvdDatabase class, we have been told in our instructions that this is the
public class that all other classes will use if they want to access the data file. However, when
we look at what the DvdDatabase class provides, we find that there are two separate functions:
1. Physically accessing the data
2. Providing logical record locking
If we tried to describe what this class does in a short sentence, we would probably have
to use the word “and”: “This class provides physical access to the data and provides logical
record locking.”
We could provide both these functions in one class, but if we split them out, then the code
will be more maintainable later. If you need to work on a method that physically accesses the
database, you will be able to go to a class that only deals with accessing the database; you will
not have to wade through all the logical locking code.
Search WWH ::




Custom Search