amadib
amadib

Reputation: 878

How to correctly start embedded JavaFX applet with specific JVM arguments

I have written a JavaFX application that includes device interaction via JNA and have no issues running it as a standalone application but when embedded within a browser, and over an extended period of time, the application gradually slows down and eventually stops responding. Using JVisualVM to profiling and monitoring the application, I can see the heap growing out of control before run out of memory and the old gen memory space full.

Monitor

Visual Garbage Collection

I was able to find another question which suggests passing arguments to the VM to force more frequent garbage collection. However I have not been able to test the suggestion due to the jvm arguments not sticking.

Modifying the MyJavafxApp.html as below:

function javafxEmbed() {
        dtjava.embed(
            {
                id: 'myApp',
                url : 'demo_javafx.jnlp',
                placeholder : 'javafx-app-placeholder',
                width : '1100',
                height : '800',
                jnlp_content : 'PD94...'
            },
            { 
                jvm: "1.6.0+",
                javafx : '2.2+',
                jvmargs: "-XX:MaxDirectMemorySize=128M -Xmx256m"
            },
            {}
        );
    }

I am unable to see the parameters as JVM Flags or JVM arguments

enter image description here

Rather they are displayed in JVisualVM under the System properties tab and under UsageTracker-AppName as a single string

UsageTracker-AppName=http://localhost:8000/target/web/demo_javafx.html: java_status_events=true jnlp_href=demo_javafx.jnlp separate_jvm=true jnlp_embedded=PD94... java_arguments=-DXX:MaxDirectMemorySize=32m,-Xmx128m,-Xms32m width=1375 javafx_version=2.2+ code=dummy.class type=application/x-java-applet id=myApp javafx_applet_id=myApp height=1000 scriptable=true codebase=http://localhost:8000/target/web/

How would I start the JVM with the arguments?

Note: I shortened the jnlp_content string. I also tried to pass the jvmargs with the -D flag and without.

Upvotes: 1

Views: 771

Answers (1)

Frederic Leitenberger
Frederic Leitenberger

Reputation: 2019

In your JNLP file you can pass VM parameters like this:

<j2se version="1.6+" java-vm-args="-Djnlp.fx=2.1+ -Djnlp.tk=swing" />

I also found that some of these parameters can be passed as applet-parameters:

<applet ...>
    <param name="javafx_version" value="2.1+" />
    <param name="scriptable" value="true" />
</applet>

Passing it to dtjava.embed() should work too.

In Deploying JavaFX Applications is described how:

var app = new dtjava.App(
        'ssh.jnlp', 
    {
        id: 'SSH',
        width: 100,
        height: 25,
        placeholder: 'SSH_application_container', 
        params: { 
            config: 'ssh_application.conf', 
        } 
    }
);

var platform = new dtjava.Platform({
    javafx: "2.1+",
    jvmargs: "-Dapp.property= ? -Xmx1024m"
});

dtjava.launch(app, platform);

The syntax you used should work too. Maybe it is just a question about which parameter to put where (as in app-parameter or vm-parameter). It also seems that the same parameter can have different names when passed in by different ways (eg. javafx: "2.1+", <param name="javafx_version" value="2.1+" /> -Djnlp.fx=2.1+), but maybe they also do different things.

Upvotes: 1

Related Questions