multithreading - EDT in Java, how does it work, does it behave like normal thread (single or mutli)? -


this beginner question: working on small chat program use tcp deliver messages, , have simple gui display it, have finished program, edt has confused me lot...

  1. does edt behave "extends thread"? imagine single thread since need worker thread process heavy logic, apparently can not thread.sleep/yield (i have while loop reading message outputstream , append jtextarea, running in main thread, tried terminate while loop set false flag , yield main thread, did not work.)

  2. i not sure how listener works, if have write it...i start thread each listener, hear process it...but wrong because make edt multithread ( lot of ears ) singlethread during process ( 1 brain )

this must me lacking knowledge!! because in head can not figure out how fire event... pressed button , java knows? must missed something.

my first time post question, hope clear

the event dispatching thread thread other thread in java.

it responsible dispatching events , repaint requests (and few other things, running synchronized runnable). action take blocks edt stop processing these events, making application has hung ... because has.

all interactions ui component must executed within context of edt. means should never try , create or update ui component thread other edt.

if need actions blocking or time consuming, should use thread. swingworker excellent place start.

adding listeners component not create more threads. edt post event notifications listeners (this incredibly shortened explanation, concept sound), 1 of reasons why should never block edt.

how events raised depends on component. mouse , keyboard events example, posted event queue native portion of code dependent on os/implementation (as understand it, coming toolkit, wrong).

actionperformed events raised jbuttons may executed directly against listener (not dispatched via event queue), within edt. raised number of events, typically caused mouse clicks , special key events. jbutton notified of these because registers event queue.

while getting understanding of workings goal, need ask yourself, matter (in short term)? know how electricity gets light switch light? or care does?

understand rules required use (don't stick sharp objects power points) , let understanding come become more confident.


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -