Writing Multithreaded Applications with the Messaging Access SDK
Table of Contents | Previous | Next | Index

Messaging Access SDK Guide


Appendix A
Writing Multithreaded Applications with the Messaging Access SDK

This appendix provides some important information for developers who want to take advantage of multithreading in their messaging applications.

The Java Messaging Access SDK is thread-safe. Three types of Messaging Access SDK methods can share resources. The methods of each type are synchronized with each other and with one of the other types, as shown in this table.

Type Description Synchronized with

1

Protocol API commands, for example, SMTPClient.rcptTo, POP3Client.list.

Synchronized among each other and with type 3.

2

The processResponses methods.

Synchronized among each other and with type 3.

3

Methods that set options, for example, SMTPClient.setTimeout,
POP3Client.setTimeout.

Synchronized among each other and with type 2.

Using multiple threads enhances performance by allowing the client to send commands to the server for processing before completing a call to processResponses. For example, a thread that uses the IMAP4 module can invoke a call to processResponses to download a message while another thread is executing API commands.

A multithreaded application may need to provide a lock on the SDK in order to synchronize state-sensitive sequences of commands within the SMTP, POP3, and IMAP4 modules as well. For example, if two threads that are connected to the same SMTP server are used to send mail, a lock is needed to prevent both threads from sending mail at the same time. If the SMTPClient.rcptTo methods of the two threads are interleaved, the email may be sent to the wrong destination.

[Top]

Multithreading in the MIME API

In general, in the MIME API, concurrent access by multiple threads is not necessary. Multiple threads should not need to change the same MIMEMessage or other MIME objects, such as MIMEMultiPart, concurrently.

One situation that is applicable to MIME in a multithreaded environment is the simultaneous parsing of multiple messages by different threads. To do this, multiple threads can create their own instances of the MIMEParser (or MIMEDynamicParser) object or share the same MIMEParser (or MIMEDynamicParser) instance.

When multiple threads share the parser object, the client application must serialize access to the object. Different MIMEDynamicParser objects can share a single instance of the MIMEDataSink object, however.

[Top]


Table of Contents | Previous | Next | Index

Last Updated: June 3, 1998

For the latest technical information on Sun-Netscape Alliance products, go to: http://developer.iplanet.com

For more Internet development resources, try Netscape TechSearch.


Copyright © 1999 Netscape Communications Corporation.
This site powered by: Netscape Enterprise Server and Netscape Compass Server.