just learnd the SwingWorker
and have a question
( i have search for a answer to this but non specifically address this setup)
Im creating a small server that will have like max simultaneous 2-3 connections only.
Im using a Jframe
that have the inner class SwingWorker
In the SwingWorker doInBackground()
i have the:
while(true) {
Socket client_socket = listen_socket.accept();
Connection con = new Connection(client_socket, "name");
Future<Connection> future = es.submit(con , con );
tasks.add(future);
}
The Connection
is a runnable
and declared as a subclass in SwingWorker
.
Before the runnable
has completed it write an entry in the SQL.
How can then this runnable before it dies send a heads-up to Jframe
event dispatch thread.
and the Jframe
will check the SQL for the new entry and display it to user.
what is best to do:
1 - create an interface witch all runnable can send messages to Jframe
event dispatch thread.
2 - use SwingWorker
insted of runnables
for all new connections and have Done()
call a method in server SwingWorker
that call method in Jframe
using EventQueue.invokeLater..
3 - or use a PropertyChangeListener (somehow no sure)
4 - Let each runnables have s ref to Jframe
and do EventQueue.invokeLater..