Calling a method from one thread to another to execute in the other thread
I'm making a server in java that has a MySQL connection in another thread, so that it's event driven and won't block the main thread.
So far it works well, it works great for queries that don't return (insert, etc) but I'm not sure how to implement a callback method that will run in the other thread. If I simply call a method from the database connection thread, that method is run in that thread.
What would be the best way to do this?
If not, perhaps your DB thread could implement a command/query pool and for each command/query be able to call a given object's callback method using reflection. This will allow non-blocking command queueing and notification on command/query completion.