just get to know SwingWorker and ask a question
(I have a search for the answer to this question, but not specifically for this setting)
I am creating a small server that will have a maximum number of simultaneous 2-3 connections.
Im using Jframe which have SwingWorker inner class
In SwingWorker doInBackground() , I have:
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); }
Connection is runnable and is declared as a subclass of SwingWorker .
Before runnable completes this, write an entry in SQL.
How can this happen when this happens before he dies, send heads-up on the Jframe stream.
and Jframe will check the SQL for the new record and display it to the user.
what is better to do:
1 - create an interface in which all runnable can send messages to the Jframe stream of the event stream.
2 - use the SwingWorker insted from runnables for all new connections and Done() call the method on the SwingWorker server, which calls the method in Jframe using EventQueue.invokeLater..
3 - or use PropertyChangeListener (somehow not sure)
4 - Let each runnables have s ref up to Jframe and do EventQueue.invokeLater..
source share