Skip to main content

Stopping J3D Threads

5 replies [Last post]
nitro
Offline
Joined: 2004-09-12

Hello

I have got an application which can open several windows. I have set them to dispose on close. Each window has its own Java3D scenegraph an views, canvases etc. If i now close a window the java3d threads do not stop how can I manually stop them on the window closing event. What Threads do I need to stop and where can I access them.

-nitro

Message was edited by: nitro

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kcr
Offline
Joined: 2004-03-17

If each Canvas3D has its own VirtualUniverse (i.e., you aren't sharing scene graph information between canvases), then it's pretty easy to clean up.

If you are using SimpleUniverse, you can call simpleUniverse.cleanup().

If you are creating your own VirtualUniverse, the following code (extracted from SimpleUniverse.cleanup()) can be used:

view.removeAllCanvas3Ds();
view.attachViewPlatform(null);
virtualUniverse.removeAllLocales();

This should cause all per-view/per-universe threads to be cleaned up for that view & universe.

-- Kevin

nitro
Offline
Joined: 2004-09-12

I do not share scenegraph informations beetween the Canvas3Ds and I did what you recommended but there is still something running. And I am quite sure it is something from J3D bcause if I do not add a Canvas3D (ie. not use any J3D) to my window everthing works fine and after the last window has closed the jvm exits.

Any suggestions?

kcr
Offline
Joined: 2004-03-17

It looks like you have discovered a bug in Java 3D. I will file an issue, since I have a trivial test program that reproduces the bug. In the mean time, try changing the order such that you call removeAllLocales() first and let us know what happens.

Btw, you will still need to call System.exit() when the last window is closed, since the Java 3D threads are not daemon threads and there are at least two global threads that do not ever exit once Java 3D has started.

-- Kevin

nitro
Offline
Joined: 2004-09-12

I do not call System.exit(). Because I have set the defaultOnClose Action of my Windows to DISPOSE_ON_CLOSE. In this case as soon as all windows are closed the jvm shuts down. Except that some java3d threads are running. So if I not call System.exit() after my last windows closes that may be the problem and not a bug.

As much as I understand there are two Java3D threads that are used by all windows (in my case i.e. although I am not sharing scene graph information and build up my own universe in each window they use some same threads). So it is not possible (or not desired/recommended) to stop these threads on the window closing event because other windows may need this threads.

That leads to that I have to count how many windows are open and to call System.exit when the counter reaches 0.

Am I correct in these assumptions?

kcr
Offline
Joined: 2004-03-17

> That leads to that I have to count how many windows are open and to call System.exit when the counter reaches 0.

Yes, that's pretty much what you will need to do.

-- Kevin