I have many threads using the below interface ServerMessage
If many threads call the dataChanged()
at the same time im
using the SwingUtilities.invokeLater
to fire of the job.
My feeling was that this would hold but could not more then
one thread enter the dataChanged()
and reassign the runnable
before the SwingUtilities.invokeLater(runnable);
is processed?
Maybe i should put a lock on the runnable
like this.
synchronized (runnable) {
work...
}
And what about the sO
wouldn't that one also change when next thread enter?
My interface used by many threads
public interface ServerMessage{
public void dataChanged(ServerEventObjects se);
public void logChanged(String txt);
}
This is the interface method
@Override
public void dataChanged(final ServerEventObjects sO) {
Runnable runnable = new Runnable() {
public void run(){
// create new ServerEventObject to avoid making changes to original.
// could clone() it but mongoDb didn't like that
ServerEventObject serverEventObject = new ServerEventObject();
serverEventObject.eventUuid = sO.eventUuid;
serverEventObject.eventUuid = sO.message;
jTextAreaLog.append(serverEventObject.message +"\n" );
JTableModel.add(serverEventObject)
}
};
SwingUtilities.invokeLater(runnable);
}