AppletContext.getApplets

R

Roedy Green

I wrote an Applet many moons ago that uses AppletContext.getApplets to
communicate with other instances of itself on the same page.

It used to work fine. But now, if there more about 3 instances, it
seems to be able to communicate only with some of the other instances.
I am in the process of debugging this.

I suspect that in the old days all applets on a page were visible, but
now there are several independent pools of applets where the number of
instances gets large, so no longer can any one applet see everything.

Has anyone heard of any thing like this, or anything else that might
have changed that interferes with inter-applet communication?
 
R

Roedy Green

It used to work fine. But now, if there more about 3 instances, it
seems to be able to communicate only with some of the other instances.
I am in the process of debugging this.

I will have to write an SSCCE to demonstrate the bug, but from work
debugging CurrCon, it looks like and old bug in JDK 1.3 has
resurfaced.

AppletContext.getApplets returns just yourself if there are large
number of instances, where "large" has yet to be determined.
 
R

Roedy Green

I suspect that in the old days all applets on a page were visible, but
now there are several independent pools of applets where the number of
instances gets large, so no longer can any one applet see everything.

I have written an SSCCE and discovered that getApplets fails when
there are 12 or more instances on a page, at least in the Firefox
browser on Windows 7 64 bit.

Here is the proof:

/*
* [MultiInstance]
*
* Summary: Demonstrate AppletContext.getApplets bug which fails for
more than 11 instances
*
* Copyright: (c) 2014 Roedy Green, Canadian Mind Products,
http://mindprod.com
*
* Licence: This software may be copied and used freely for any
purpose but military.
* http://mindprod.com/contact/nonmil.html
*
* Requires: JDK 1.7+
*
* Created with: JetBrains IntelliJ IDEA IDE
http://www.jetbrains.com/idea/
*
* Version History:
* 1.0 2001-03-08 initial
*/
package com.mindprod.example;

import javax.swing.JApplet;
import javax.swing.JButton;
import java.applet.Applet;
import java.applet.AppletContext;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Enumeration;

import static java.lang.System.out;

// simple jar build: jar -cvfm multi.jar manifest.mf
\com\mindprod\example\MultiInstance*.class
// manifest.mf looks like this:
// Manifest-Version: 1.0
// Application-Name: MultiInstance
// Permissions: sandbox
// Created-By: 1.8.0 (Oracle Corporation)
// Main-Class: com.mindprod.example.MultiInstance

// run with multi.html
//that looks like this:
// <!DOCTYPE HTML>
// <html lang="en-CA">
// <head>
// <meta charset="utf-8">
// </head>
// <body>
// <p>Click each applet to see which others it can see, listed
on the console.</p>
//
// <object type="application/x-java-applet" data="multi.jar"
width="40" height="20">
// <param name="code"
value="com.mindprod.example.MultiInstance">
// <param name="archive" value="multi.jar">
// <param name="instance" value="1"> <!-- unique instance
identifier -->
// Applet failed to run.
// </object>
//
// <object type="application/x-java-applet" data="multi.jar"
width="40" height="20">
// <param name="code"
value="com.mindprod.example.MultiInstance">
// <param name="archive" value="multi.jar">
// <param name="instance" value="2">
// Applet failed to run.
// </object>
// ... 11 instances will work, 12 will fail.
// </body>
// </html>


/**
* Demonstrate AppletContext.getApplets bug which fails for more than
11 instances
*
* @author Roedy Green, Canadian Mind Products
* @version 1.0 2014-04-12 initial version
* @since 2014-04-12
*/
public final class MultiInstance extends JApplet
{
// ------------------------------ CONSTANTS
------------------------------

/**
* which instance on the page are we, unique string
*/
private String instance = "unknown";

// -------------------------- PUBLIC INSTANCE METHODS
--------------------------

/**
* constructor
*/
public MultiInstance()
{
}

/**
* dump out who can see what
*/
public void dump()
{

// dump out what getApplets provides
final AppletContext ac = this.getAppletContext();

// all Applets on page, possibly including us, including
non-MultiInstance
final Enumeration<Applet> otherApplets = ac.getApplets();
if ( otherApplets == null || !otherApplets.hasMoreElements() )
{
out.println( "instance " + instance + " unable to see any
other applets" );
}
else
{
while ( otherApplets.hasMoreElements() )
{
Applet other = otherApplets.nextElement();
if ( other instanceof MultiInstance )
{
out.println( instance + " can see: instance " + (
( MultiInstance ) other ).getInstance() );
}
else
{
out.println( instance + " can see: " +
other.getAppletInfo() );
}
}
}
}

public void init()
{
instance = getParameter( "instance" );

JButton t = new JButton( instance );
t.setBackground( Color.orange );
this.add( t );
t.addActionListener( new ActionListener()
{
/**
* Invoked when user clicks button
*/
public void actionPerformed( ActionEvent e )
{
dump();
}
} );
this.validate();
this.setVisible( true );
}// end init

// -------------------------- OTHER METHODS
--------------------------

/**
* which instance on the page are
*
* @return unique instance string
*/
String getInstance()
{
return instance;
}
// has no main method.
}
 
R

Richard Maher

I have written an SSCCE and discovered that getApplets fails when
there are 12 or more instances on a page, at least in the Firefox
browser on Windows 7 64 bit.

Anything in the FF Web Console or Java console? What was the error
again? Do other browsers break at 13 as well?

if you run with separate classloaders or JMS does the problem go away?
(Clearly inter-Applet communication will get harder :)

<PARAM name="separate_jvm" value="true">

<PARAM name="classloader_cache" value="false">

Cheers Richard "I hate Eric Costlow and can't understand how anyone with
such a Java anemic CV can have his job!" Maher
 
R

Roedy Green

Anything in the FF Web Console or Java console? What was the error
again? Do other browsers break at 13 as well?

FireFox, Opera and IE fail at 12+
Chrome works at 12. I have have not yet found out it it too has a
limit.
 
R

Roedy Green

<PARAM name="separate_jvm" value="true">

<PARAM name="classloader_cache" value="false">

Somebody goofed at using the same syntax for system and user
parameters. It makes every new system parm a reserved word.

If you used separate_jvm I would expect getApplets not to work. I
think that is what is happening, because you suddenly start getting
large numbers of consoles when you hit the 12 limit. It is not one JVM
per applet and it is not two JVMs either, the way you might expect
when you hit 12.

You have a common static region for communication if all Applets are
in the same JVM.

I think I will try:
<PARAM name="separate_jvm" value="false">
to see if it forces a common JVM. The applets are quite tiny and have
little overhead.

I will have to read up on classloader_cache to see how it fits in.
 
R

Roedy Green


AppletContex.getApplets returns an enumeration of all the Applets
running on the page, including yourself.

It works correctly when there are 1 to 11 instances of the Applet.

When you have 12+, the enumeration contains only 1 element, namely
yourself. You can't see any of the other Applets.

Firefox, Opera, IE all behave this way. Chrome works for n=12. I have
not done experiments for larger numbers.

I think what is happening is 12 or above, Firefox gives each Applet
not only a separate thread, but a separate JVM. Another symptom is the
appearance of multiple consoles at 12+

Either a browser should put all Applets of the same class in the same
JVM, or give you a way to force that.

Oracle, if they do anything, may just add a warning the documentation
for getApplets that it does not work for values of n+, where n is
determined by experiment.

Bugs like this give much more grief that my own bugs. I expect the
system stuff to work as advertised, and keep looking for something
wrong it my own code, and only as a last resort start exploring the
possibility Oracle erred.
 
R

Roedy Green

I have written an SSCCE and discovered that getApplets fails when
there are 12 or more instances on a page, at least in the Firefox
browser on Windows 7 64 bit.

For Firefox, Opera and IE it fails on 12+ instances.
For Chrome it fails on 13+ instances
 
R

Roedy Green

Oops. So there is no error.
Only behavior you did not expect.

jdk1.8.0/docs/api/java/applet/AppletContext.html#getApplets--

Enumeration<Applet> getApplets()

Finds all the applets in the document represented by this applet
context.
Returns:
an enumeration of all applets in the document represented by this
applet context.

It does not return ALL the Applets, only some of them, and sometimes
NONE of them but yourself. I consider that a bug. Now a lawyer would
argue about the sleazoid "context" wording to excuse the behaviour.
The docs should at least warn you that it only works up to 11
instances. Oracle instead screws you around so they don't have to
admit a problem.

You test with 2 or 3 instances. It works, so you assume it will work
for more. IT DOES NOT. And the buggers refuse to warn you. I have
wasted so much time on this that coud have been saved by adding one
sentence to the docs.
 
R

Roedy Green

<PARAM name="separate_jvm" value="true">

with 12+ instances FireFox, Opera and IE fail. Applets cannot see the
other Applets.
Chrome fails with 13+ instances.
With <param name="separate_jvm" value="false"> Chrome, ironically
fails on 12+ instances.
 
R

Richard Maher

For Firefox, Opera and IE it fails on 12+ instances.
For Chrome it fails on 13+ instances

You should be more worried about Chrome not working with NPAPI next
month (should've been this month but received a stay of execution).

Google has taken Larry out in the street and bitch-slapped him in front
of everyone and he's just taking it :-(

This is a deliberate calculated malicious attack on Java's longevity and
worst of all it is clearly gratuitous from any technical viewpoint.

But with demonstrable dickheads calling the shots at Oracle Applet
engineering and this newsgroup full of numpties getting their jollies
over lambdas what do you expect?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top