Mishums
Mishums

Reputation: 19

How to separate AnimationTimer from the JavaFX application thread?

I'm working with Canvas - and drawing on the GraphicsContext of the canvas from multiple simple thread doesn't work so smooth...

The only normal way is working with AnimationTimers - but they are not working as separate threads. When I call wait() inside the animation timer, it stops the whole application.

There is a way to separate the AnimationTimers from the application's main thread? So it will run as independent thread and wait without stopping the whole application?

Upvotes: 0

Views: 671

Answers (1)

jewelsea
jewelsea

Reputation: 159416

There is a way to seperate the AnimationTimers from the application's main thread? So it will run as independent thread and wait without stopping the whole application?

No, you can't run an animation timer on it's own thread. Animation timers provide callback handlers that are invoked on every pulse of the JavaFX system on the JavaFX application thread.

When I call wait() inside the animation timer, it stops the whole application.

Don't do that...

drawing on the GraphicsContext of the canvas from multipe simple thread doesn't working so smooth...

You shouldn't be calling on a graphics context from multiple threads. The graphics context isn't a multi-threaded construct, its API is built to be invoked only from the JavaFX application thread once the canvas is attached to a live scene.

Upvotes: 1

Related Questions