I seem to vaguely recall some JVMs have a limit on how many strings
you can intern. I wondered
1. what that limit was.
2. what those JVMs were.
3. how they fail. do the cause an exception or do they simply stop
interning and just return the uninterned String.
I wrote this little test program. I wonder if could run it on any
JVMS you have and report back if any fail.
/**
* Test how many String the JVM can safely intern.
*
* @author Roedy Green
* @version 1.0
* @since 2003-08-21
*/
public class InternTest
{
/**
* How many strings you want to intern for the test.
*/
public static final int n = 80000;
/**
* test harness
*
* @param args not used
*/
public static void main ( String[] args )
{
String[] hold = new String[ n ];
// build list of interned strings
for ( int i=0; i<n; i++ )
{
try
{
hold[i] = Integer.toString(i).intern();
}
catch ( Exception e )
{
System.out.println( "intern exploded at " + i );
System.exit(1);
}
}
// make sure they were really interned.
for ( int i=0; i<n; i++ )
{
if ( hold[i] != Integer.toString(i).intern() )
{
System.out.println( "intern failed at " + i);
System.exit(1);
}
}
System.out.println( "intern good for at least " + n + "
Strings.");
}
}
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
Brad BARCLAY - 22 Aug 2003 16:57 GMT
> I seem to vaguely recall some JVMs have a limit on how many strings
> you can intern. I wondered
[quoted text clipped - 5 lines]
> I wrote this little test program. I wonder if could run it on any
> JVMS you have and report back if any fail.
Sure thing. As I have a number of odd JRE's installed here, I tested
it under all of them for you.
First off, the Java Runtime Environments:
IBM Java 1.1.8 for OS/2
IBM Java 1.3.1 for OS/2
GoldenCode Java 1.4.1 for OS/2
Innotek Java 1.4.2 for OS/2
Sun Java 1.4.2 for Linux
All of these runtimes completed the intern() of 80000 Strings without
fail, _except_ for the IBM Java 1.1.8 JRE, which threw the following
exception:
java.lang.OutOfMemoryError: string intern table overflow
at InternTest.main(Compiled Code)
As this is an Error, and not an Exception, your catch block didn't get
to run. I modified your code to catch all Throwables instead, at which
point it output:
intern exploded at 50741
HTH!
Brad BARCLAY

Signature
=-=-=-=-=-=-=-=-=
From the OS/2 WARP v4.5 Desktop of Brad BARCLAY.
The jSyncManager Project: http://www.jsyncmanager.org
Neil Campbell - 23 Aug 2003 02:29 GMT
> I seem to vaguely recall some JVMs have a limit on how many strings
> you can intern. I wondered
[quoted text clipped - 5 lines]
> I wrote this little test program. I wonder if could run it on any
> JVMS you have and report back if any fail.
For info, Blackdown-1.4.1-01 on Linux reports that 'intern good for at least
80000Strings.'

Signature
Neil Campbell
batneil[AT]lineone[DOT]net
http://www.thebatcave.org.uk