• Post Reply Bookmark Topic Watch Topic
  • New Topic

Code not running inbetween Thread.sleep() methods  RSS feed

 
Heg Lachher
Greenhorn
Posts: 28
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, i have some code below and the code is not running inbetween every Thread.sleep() method in the for loop; it is shows output once all thread.sleep() methods are done.

Does anybody know why this is happening?
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The value of the progress bar is maintained by some data model the progress bar has. the data model triggers an event when the value changes, and the gui part of the progress bar responds to the event. But your action performed method is consuming the event dispatch thread so the value change event doesnt get through until the action performed method finishes.

you should never perform lengthy actions in an action performed method or any method on the event thread. you need to push it into a background task. See:
http://docs.oracle.com/javase/tutorial/uiswing/concurrency/worker.html
http://docs.oracle.com/javase/tutorial/uiswing/components/progress.html
 
Heg Lachher
Greenhorn
Posts: 28
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve Luke wrote:The value of the progress bar is maintained by some....

Thakns!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!