Using threads for asynchronous behavior, Using threads with jolt – HP NonStop G-Series User Manual
Page 84
The typical usage is to make the following call in all long running code segments or potentially time-consuming loops:
Thread.currentThread.yield();
Without sending this message, the threads used by the Jolt library may never get scheduled, and as such, the Jolt operation will be
impaired.
The only virtual machine known to use non-preemptive threading is the Java Developer's Kit (JDK version 1.0, 1.0.1, 1.0.2) machine
running on a Sun platform. If you want your applet to work on JDK 1.0, you must make sure to send the yield messages. As mentioned
earlier, some methods contain yields. An important exception is the System.in.read method. This method does not cause a thread switch.
Rather than rely on these messages, we suggest using yields explicitly.
Note
Sun has indicated that JDK 1.1 will implement preemptive threads, and should alleviate the
requirement for yields. Code that includes yields will continue to work; code without yields
will begin working with the JDK 1.1 release.
Using Threads for Asynchronous Behavior
You can use threads in Jolt to get asynchronous behavior that is analogous to the tpacall() function in TUXEDO. With this capability, you
do not need a asynchronous service request function. You can get this functionality because Jolt is thread safe. For example the client Jolt
application can start one thread that sends a request to a TUXEDO service function and then immediately starts another thread that sends
another request to a TUXEDO service function. So even though the Jolt tpacall() is synchronous, the application is asynchronous because
the two threads are running at the same time.
Using Threads with Jolt
A Jolt client-side program or applet is fully thread-safe. Jolt's support of multi-threaded applications includes the following client
characteristics:
Multiple sessions per client
●
Multithreaded within a session
●
Client application manages threads, not asynchronous calls
●
Performs synchronous calls
●
The following program illustrates the use of two threads in a Jolt application.
Example 6-10. Using Multithreads with Jolt (ThreadBank.java)
/* Copyright 1996 BEA Systems, Inc. All Rights Reserved */
import bea.jolt.*;
public class ThreadBank
{
public static void main (String [] args)
{
JoltSession session;
try
{
JoltSessionAttributes dattr;
String userName = null;
String userPasswd = null;
String appPasswd = null;
String userRole = null;
// fill in attributes required
dattr = new JoltSessionAttributes();
dattr.setString(dattr.APPADDRESS,"//bluefish:8501");