java - does swing view needs synchronized methods if its set by new threads in controller -
There are actually more than 1 question.
Looking at the model view and controller (I find a lot - see your controller knows, and the controller knows.)
Whether the new thread in the controller is original Can be removed from the form - with the As if Anything in the swing to run on EventQueue is If you have swing There is no way to tell, it will already be running there (such as an action listener) If you do not know if you are in the event queue, then Be very careful about this; If you do not have to check your code, then my experience is that the swinging UI will only be a little flaky, sometimes with uneven disparities. There is no easy way around eye-eye eyes on each line of code. Actually, there is. Everything at the EventQueue, then you will not have to worry. If you are, you are not doing a lot of work outside the swing anyway, then you probably have the cost of loss of speed to avoid multithreading problems. If your non-swing work is broad but simple, then use the swingwire class, it gives you an extra thread in highly controlled conditions and will save you a lot of grief. Your classes (see and control) are free from threads, and should work fine to run in a thread. Do not confuse sections and threads (I believe, I was tempted to firing the controller to close threads in every direction, but you have to be prepared to be careful about lot and multilevel information Everything about it will be known.) If you multithread, EventQueue may be a bit easier because you do not have to just keep the field referenced there - it is a dangerous sea. Not a single island of threading. On the other hand, no do any synchronization there; You will block your UI. You can launch threads from there and you may just need to avoid blocking. (Once you start multithreading, it is difficult to stop.) new runnable () {(..) run () {}} or in some "swing methods", to make it properly ? Maybe with
timer or
invokeLater () ? The other thing is that this new thread has started - when it is running on the straight view, set some
JTextField s (and so on) - what do the ways
setThatTextFieldWithNewValue (msg) needs to be synchronized as a result of the call from the required thread? If so - is there any better way that gives less time to spend time about less coupling and essential synchronization?
EventQueue.isDispatchThread () Will tell. When you know that you do not know, refer to the way you use swing class or
EventQueue.invokeLater () or
invokeAndWait , if you see the result Required (this should be done with the
main method.)
Comments
Post a Comment