Java Reference
In-Depth Information
Summary
In this chapter, we discussed the Denny's DVDs socket implementation. We also provided a
brief overview of the different types of sockets, and the various types of TCP socket develop-
ment strategies. We laid out the application protocol for our socket implementation and
demonstrated the Command pattern with the help of Java enums. The choice of sockets as the
network protocol in your exam solution should not be perceived as something esoteric and
frightening that is to be avoided at all costs. Even though most students opt to not develop a
socket solution, we believe that the choice isn't any more challenging than an RMI solution
and should be fairly straightforward, given the sample code base that accompanies this text.
Sockets are a technology that underlies most networking protocols. Most of the cool new tech-
nologies, such as web services and EJBs, ultimately rely on sockets. As we have discussed, even
RMI is built on top of sockets. So you would be well served to become acquainted with sock-
ets, if only to help deepen your understanding of these other networking technologies. The
next chapter covers the graphical user interface (GUI) for the Denny's DVDs application.
FAQs
Q Do I need to implement a multithreaded socket server?
A Yes. The certification exam requires that the server allow multiuser access. If you use a
single-threaded solution, then there will never be a way to demonstrate concurrent
access. Your application will block serially until each request is resolved one at a time.
This may be an interesting solution and will circumvent the need to figure out a lock-
ing strategy, but one that Sun will not permit.
Q Should I utilize a thread pool for the socket server implementation?
A This is completely up to you. You could do so and it would be a good practice. Every
time a new connection is accepted, our server spawns a new thread to handle the
request. However, creating and destroying threads is not a free lunch. On a really busy,
highly trafficked server, it might be better to control the creation of threads. A thread
pool will instantiate a set number of threads, a number that can be calibrated based on
your application performance requirements, upon startup. When the server receives a
new request, it is serviced with one of the threads from the pool. When the request is
completed, the thread is returned to the pool for later use. A thread pool will eliminate
the overhead associated with creating and destroying new threads. We do not make
use of a thread pool in Denny's DVDs and you will not have to implement a thread pool
for your certification project since the exam does not require that your server perform
well under a heavy load.
Q What is meant by TCP sockets being a connection-oriented protocol?
A Sometimes in the literature, the term “connection-oriented” will be used when refer-
ring to TCP sockets. What this means is that before communication can occur between
the endpoints, a connection must exist. Contrast this with UDP sockets, a connection-
less protocol.
Search WWH ::




Custom Search