Right method to exit/dispose on linux

classic Classic list List threaded Threaded
30 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Re: Right method to exit/dispose on linux

elect
So, to sum up and understand, why does it work with the animator? Because is it itself a thread that keeps the application running?
Reply | Threaded
Open this post in threaded view
|

Re: Right method to exit/dispose on linux

gouessej
Administrator
http://jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc/com/jogamp/opengl/util/Animator.html
The Animator execution thread does not run as a daemon thread, so it is able to keep an application from terminating.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Right method to exit/dispose on linux

elect
gouessej wrote
http://jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc/com/jogamp/opengl/util/Animator.html
The Animator execution thread does not run as a daemon thread, so it is able to keep an application from terminating.
I don't know exactly what the daemon attribute means, however, let me get it, so basically this means that we end up having both the main thread and the animator thread running where the only things that prevents the main from terminating is the animator itself.

This also would mean that in order to quit properly, I just have to terminate (stop?) the animator and then the main will terminate as well?
Reply | Threaded
Open this post in threaded view
|

Re: Right method to exit/dispose on linux

jmaasing
Just try my example, as far as I can tell it does exactly what you are asking for

It takes a little while for the main thread to stop because of the internal clean up but the application will exit cleanly, no need for any System.exit calls or anything. Just close the window by clicking the close button and wait a few seconds.
Reply | Threaded
Open this post in threaded view
|

Re: Right method to exit/dispose on linux

elect
:) I tried that, jmaasing, but I got this warning in the console (on the window closing)

Thread[main-Display-.windows_nil-1-EDT-1,5,main]: Warning: Default-EDT about (2) to stop, task executed. Remaining tasks: 1 - Thread[main-Display-.windows_nil-1-EDT-1,5,main]

Is that normal?

That's why I actually wanted also to understand the complete interaction between the main and the animator

Ps: i just modified your code by adding "final" to the animator declaration
Reply | Threaded
Open this post in threaded view
|

Re: Right method to exit/dispose on linux

jmaasing
elect wrote
:) I tried that, jmaasing, but I got this warning in the console (on the window closing)

Thread[main-Display-.windows_nil-1-EDT-1,5,main]: Warning: Default-EDT about (2) to stop, task executed. Remaining tasks: 1 - Thread[main-Display-.windows_nil-1-EDT-1,5,main]

Is that normal?

That's why I actually wanted also to understand the complete interaction between the main and the animator

Ps: i just modified your code by adding "final" to the animator declaration
I haven't seen that warning but I use OSX so I'm not sure if it is normal on other platforms. I don't understand what it is warning about. Maybe some one can enlighten us.

Way to go with "final" - I usually write final on everything but removed it in the example to make it look cleaner :-)
Reply | Threaded
Open this post in threaded view
|

Re: Right method to exit/dispose on linux

gouessej
Administrator
In reply to this post by jmaasing
When using Java Webstart, you're still forced to call System.exit(0) as far as I know.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Right method to exit/dispose on linux

elect
gouessej wrote
When using Java Webstart, you're still forced to call System.exit(0) as far as I know.
Yep, that solved.

Thanks you all, guys
Reply | Threaded
Open this post in threaded view
|

Re: Right method to exit/dispose on linux

jmaasing
In reply to this post by gouessej
gouessej wrote
When using Java Webstart, you're still forced to call System.exit(0) as far as I know.
I wish the forum had a flag to "report content as appropriate"  I learn something new every day.
Reply | Threaded
Open this post in threaded view
|

Re: Right method to exit/dispose on linux

elect
So, I tried to port the method to my program, adding the glViewer to a JFrame



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package core;

import com.jogamp.opengl.util.Animator;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import rendering.GlViewer;

/**
 *
 * @author elect
 */
public class Lope extends JFrame {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

        lope = new Lope();
    }

    private static Lope lope;
    private GlViewer glViewer;

    public Lope() {

        glViewer = new GlViewer();

        add(glViewer.getNewtCanvasAWT());

        final Animator animator = new Animator(glViewer.getGlWindow());
       
        addWindowListener(new WindowAdapter() {

            @Override
            public void windowClosing(WindowEvent windowEvent) {
               
                animator.stop();
            }
        });
       
       

        setSize(1024, 768);

        setVisible(true);
       
        animator.start();
    }

    public static Lope getIstance() {
        return lope;
    }

    public GlViewer getGlViewer() {
        return glViewer;
    }
}



But I still get

X11Util.Display: Shutdown (JVM shutdown: true, open (no close attempt): 3/3, reusable (open, marked uncloseable): 0, pending (open in creation order): 3)
X11Util: Open X11 Display Connections: 3
X11Util: Open[0]: NamedX11Display[:0, 0x7f178809d6d0, refCount 1, unCloseable false]
X11Util: Open[1]: NamedX11Display[:0, 0x7f17880d9e00, refCount 1, unCloseable false]
X11Util: Open[2]: NamedX11Display[:0, 0x7f17d846d440, refCount 1, unCloseable false]
12