Global Positioning System Reference
In-Depth Information
11.7
Server Tuning
A server machine usually has massive CPU power to handle a large number
of synchronous client accesses. Nevertheless, the server has to make sure
that the server-side objects accessed and modified by client calls are served
in an ordered manner to ensure that the ServerObject s are always in a
clean state. Since client method invocations can take their time to return,
the server should synchronize its services. Some Java applications add
(un)locking methods for the client. This can be risky and will not be used
for RO clients.
11.7.1
Threading (in a Nutshell)
For thread implementations, the following aspects need to be considered:
1. Identify the objects that can be accessed by concurrent threads. Keep
in mind that each remote client represents an independent thread.
2. Ensure that a thread can not modify an object while another thread
is modifying it. Registering a client should be finished, before an-
other client can start registering. This can be achieved by using a
synchronized(object) f ... g block. The JVM ensures that only
one thread can access the synchronized object. When the code is
entering this block, other accesses to this object are blocked/locked
and unblocked/unlocked upon leaving. A lock only controls access to
the synchronized code.
3. Introduce synchronized methods in the object being accessed concur-
rently which needs internal book keeping. A synchronized method
automatically uses synchronized(this) to block this object with
the method. The object should introduce object states, which can
be used in synchronized blocks to control the program flow. Other
threads can use the object states to control their flow. Method names
like .waitToStart and .waitToEnd should indicate that these meth-
ods implicitly call Object.wait() . Method pairs can imply do and
undo operations for object states. These methods support the co-
ordination of many threads and leverage (make use of) the internal
java.lang.Object s states and triggers controlled by an internal sched-
uler.
Since the construction of a thread is a complex JVM operation every server
should have a concept to deal with many threads.
 
Search WWH ::




Custom Search