Synchronized Drag and Drop?!?

All game events happen on the game thread.
All gui events happen on event dispatch thread, as far as i know.

Lets say I want do drag and drop. i.e. drag an item in my inventory to my equipment.

Exporting involves getting game data. However, since exporting happens on the EDT, a race condition is possible. The same applies with importing.

My solution is to:

  1. Ignore race conditions and delay data manipulation until later.

  2. Push that final code to the game loop with something like this:


Game.invokeLater(Runnable run);

  1. Re-check and continue/change data if everything is good

Only issue is this method:


public boolean importData(TransferHandler.TransferSupport support);

This the final import code. What should I return? Since I am offloading the actual import code to the game loop, there is no way for me to know if I am still importing data.

Handle this the same way keyboard and mouse input are handled. Through polling. Change the UI motions in local variables and then in your game loop poll for UI events and copy that data that was gathered asynchronously into the “polled data” variables and act on those.

[quote=“tariqbroadnax,post:1,topic:58805”]
Huh? How is there no way? You could poll from one thread to the other, or better yet just notify the other thread when it’s done. There are a ton of ways for you to know when you’re done importing the data. Have you read any concurrency tutorials?

You are not supposed to stall the EDT.

Just do the minimal validation you need to do on the EDT (eg. extracting from the TransferSupport what you need to pass to your Game thread) and just return true. Pop up an error later if that assumption proves to be incorrect?

None of the things I mentioned require stalling the EDT.