NonStop JMS User's Manual (NonStop JMS 2.0+)
NSJMS and JMS Client Applications
NonStop Server for Java Message Service User’s Manual—522356-002
3-12
Threading
This code fragment creates a message listener for a topic:
import javax.jms.*;
public class MyClass implements MessageListener
{
public void onMessage(Message message)
{
System.out.println("The message is "+message);
.
.
.
}
}
.
.
.
MyClass listener =new MyClass();
topicSubscriber.setMessageListener(listener);
Threading
You can use JMS with multithreaded Java applications. Although threading is
supported, the send calls block the process during send operations and the receive
calls will support the non-blocking features of SQL/MX during receive operations when
sqlmx_nowait is set to on.
Two NSJMS property values specify the threading behavior. The Database.Timeout
property value is the time in milliseconds during which stream selects block for new
messages before a timeout. The Database.Delay property value is the time in
milliseconds that the thread is delayed after a timeout.
Setting the Database.Timeout and Database.Delay values below 1000 gives
more responsive threads because the read is stopped and restarted frequently, which
allows other threads to run. This responsiveness costs in system throughput, however,
because the read is tried several times for each message. In single-threaded
applications and applications where inter-thread responsiveness is not critical, use
Database.Timeout and Database.Delay values greater than 1000 so that the
JVM is not busy waiting. When messages are not available, the process blocks,
allowing other processes to run.
Send Operations
Queue send operations and Topic publish operations block the process for a short
duration during a SQL INSERT operation.
Receive Operations
Queue receive operations and Topic receive operations support the non-blocking
features of SQL/MX during receive operations only when the system property
sqlmx_nowait is set to on. The non-blocking features of SQL/MX are useful in multi-