Combining Java swing and java3d: concurrency performance issues

I combine swing with Java 3D The operation of swing component shall be completed using event scheduler thread, while the operation of Java3D component shall be completed in behaviourschedulerthread

Java 3D renders the scene and then performs all the actions associated with the scene

I enabled mouselistener on canvas 3D The event is published to the AWT event queue Then I want to modify the Java 3D environment based on these events, so I use a special behavior in which I can publish runnable This ensures that runnable is executed during the behavior loop of Java3D (and nothing is modified during the render loop)

Suppose some operations in the behavior want to modify the swing model Then I have to release a new runnable on EDT

Is this the right thing to do?

Using this technology, I encountered many problems with the mouse listener I updated a point in the java3d model, and I updated the swing GUI

Update: the problem can be more clearly defined as follows:

I have a JButton "spin Cube", which has an actionlistener Once the actionlistener is triggered, it pushes the awtevent to the Java 3D behavior Once the behavior is triggered, it will modify the scene graph, and then modify JButton actionlistener and text to make it "stop rotation"

>Click JButton twice. > The first awtevent is scheduled to spinactionlistener The cube starts to rotate and changes JButton actionlistener to stopspinningactionlistener. > The second awtevent is sent to stopspinningactionlistener The cube stops rotating and changes JButton actionlistener to spinactionlistener

The actual situation is as follows:

>Click JButton once and JButton twice Both awtevent are scheduled to spinactionlistener This will create a runnable in the j3d behavior to execute. > The first awtevent starts a timer to rotate the cube Then publish a runnable to EDT to modify the button. > The second awtevent starts a timer to rotate the cube The cube will rotate twice Then publish a runnable to EDT to modify the button

Obviously, I should not rely on the sequential processing of awtevent Because of any swingutilities Invokeandwait () causes deadlock, so I have to wait for this behavior in EDT

Solution

Which wakeupcriterion is used to wake up your special behavior object?

The source code of Java 3D includes utility classes

com.sun.j3d.utils.behaviors.mouse.MouseBehavior/MouseRotate

It monitors the awtevents of canvas 3D You can choose one of two options:

> MouseListener with WakeupOnBehaviorPost or > WakeupOnAWTEvent.

This code example may be helpful

Through swingutilities Invoker from behavior Starting swing component updates within the processstimulus method should not cause any problems

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>