Hi,
I've been using Kryonet with my Libgdx app so far nad ran into problems: when I update some UI controls from kryonet's client listener, app crashes occasionally. This is due to thread concurrency problems. Now I was thinking how to synchronize main libgdx thread and kryonet thread. My question is: what is the best practice, how do you guys do it?
I've tried doing it like this:
Gdx.app.postRunnable(new Runnable() {
@Override
public void run() {
client.update();
}
});
This ensures that the kryonet's client update gets executed within the libgdx's thread. However, there is one problem: connect() method must be ran in a separate thread, or else this happens:
Exception in thread "LWJGL Application" java.lang.IllegalStateException: Cannot connect on the connection's update thread.
Now my problem is that the connect() method calls onConnect notifier method which in turn adjust UI controls in my app. This again causes concurrency problem. So my question is: how to resolve this problem?