MATLAB: Do I receive a Java Exception when starting MATLAB 6.5 (R13) or later

exceptionjavaMATLABsize;stackstacksize

I receive the following Java Exception when starting MATLAB 6.5 (R13) or later:
Failed to start the Desktop: Java exception occurred:
java.lang.OutOfMemoryError: unable to create new native thread
at java.lang.Thread.start(Native Method)
I would like to know if the problem is related to stack size.

Best Answer

This error is due to the way that the JVM is using memory on your system. There are several solutions to this problem. Platform specific solutions are as follows:
1. Create a java.opts file for the Java VM (for Windows and UNIX):
===========
In the following directory
$MATLAB/bin/$ARCH create a java.opts file. In that file, add a line such as:
-XX:ThreadStackSize=8192
Where $MATLAB is your root MATLAB directory and $ARCH is your architecture.
For example by default:
$MATLAB
Windows - C:\MATLAB6p5
UNIX, Linux - /usr/local/MATLAB6p5
Mac OS X - /Applications/MATLAB6p5
$ARCH
alpha, glnx86, hp700, hpux, ibm_rs, mac, sgi, sol2
2. Lower your stack limit (for UNIX only):
===========
MATLAB will work with 16MB stack limit. To lower the limit, issue the following command at the UNIX prompt
limit stacksize 16384
this can be done as part of your login script.
3. Keep your stack limit high, but create an alias or a wrapper script for running MATLAB that lowers the Java stack size to something smaller when starting MATLAB (for UNIX only):
===========
The script should do the same thing as option number 2.
4. Run MATLAB without the Java VM (for Windows and UNIX):
===========
To do this, type the following at the UNIX prompt
matlab -nojvm
NOTE: If you select option number four, you will not have access to the Java features of MATLAB such as the desktop, editor, on any other java enabled feature of MATLAB.