Solaris Multithreading Options


Command-line flag:
     jdk-tool [-green | -native] options...
jdk-tool is either java or appletviewer.
Environment variable:
% setenv THREADS_FLAG [-green | native]
Green threads are the default. The command-line flags, if specified, override the setting of the THREADS_FLAG environment variable.

How do you decide which threading option to use?

The Solaris Java Development Kit includes two implementations of thread-handling software. The default threads implementation is called green threads; a native threads implementation is also available.

Native threads can provide several advantages over the default green threads implementation, depending on your computing situation. Among the benefits of using the native threads are:

In some instances, it may be advisable to use the default green threads. Native code that is not multithread safe (MT-safe) may not work correctly with native threads. In general, if you aren't using the native Solaris threads mechanisms directly, then you need to compile your native code with the option -D_REENTRANT to make sure that they work correctly in a threaded environment. You may also need to use reentrant versions of certain Solaris interfaces.

Specific information concerning multithreaded programming on Solaris may be found in the Multithreaded Programming Guide of the Solaris Software Developer AnswerBook. This information is also available on the web site.

It is possible that thread-synchronization bugs in code that you run may be hidden when using green threads, but may manifest themselves when run under native threads. You should consider this possibility if your code runs differently under the two threads packages.

How do you specify the threading option you chose?

All the tools in the Solaris Java Development Kit use green threads by default. To specify that native threads should be used, you can set the THREADS_FLAG environment variable:

% setenv THREADS_FLAG native

You can revert to use of green threads by setting THREADS_FLAG to the value green:

% setenv THREADS_FLAG green

You can also select the thread option by using the -native or -green command-line flag with the JDK tools. The threads flag must be the first option specified on the command line.

The command-line flags can be used as in these examples:

% java -native mypkg.MyClass
% appletviewer -green MyApplet.html

The command-line flags override the setting of the THREADS_FLAG environment variable.