Each service component must implement the CtsServices::GenericService interface methods. This section describes how to implement the CtsServices::GenericService in C++ and Java.
Be careful of consuming CPU cycles
If
your service will perform background processing, your implementation
must have access to a thread-aware sleep mechanism. In Java, call
the java.lang.Thread.sleep() method, or use a
monitor object and call the Object.wait() method.
In C, C++, or PowerBuilder, EAServer provides
the JagSleep routine. The run method
in your service must call one of these APIs periodically to suspend
execution of the current thread. Otherwise, your service will dominate
the server’s CPU time and prevent other components from
executing.
If coding service components in PowerBuilder, code your component’s run method to call the JagSleep C routine; do not use the PowerBuilder timer event, which may suspend the EAServer process.
Services with a client interface
If your component runs as a service and also provides a client
interface for remote invocations, beware that the run method
may not have executed when the first client request arrives. run is
called on a different thread after start returns;
client invocations may arrive between the return from start and
the invocation of run, and initialization performed
in run may not have completed when the remote
method executes on a different thread. To avoid problems, use one
of these approaches:
Do not code remote methods that rely on initialization performed in the run method. Initialization can be performed in the start method, which is guaranteed to complete before client invocations arrive.
Use a synchronized boolean variable that is set when run has performed necessary initialization, and code remote methods to check this variable and wait for it to be set before executing code that relies on initialization performed in run.