Results 1 to 8 of 8
- 09-02-2009, 11:54 PM #1
Member
- Join Date
- Sep 2009
- Posts
- 3
- Rep Power
- 0
calling thread.sleep stalls main gui
Hi,
When I call thread.sleep in another thread, it seems to stall even the main event thread (the gui doesn't update itself for a long period of time). I was wondering if calling thread.sleep influences any of the other threads that may be running at the same time?
- 09-03-2009, 12:04 AM #2
It could. If you call a Thread.sleep when handling a button click, for example, it will freeze that button's UI for as long as you sleep.
If you have a sleep within the run method of a thread then i can't see why it would effect other threads unless they are deadlock or competing for a shared resource that you have locked.My Hobby Project: LegacyClone
-
Agrees with MrMatt above. If however you want a more specific example then please post some sample code that demonstrates your problem.
Edit: also, if this is a Swing program, please have a look at this tutorial: Concurrency in Swing
Much luck and welcome to the forum.
- 09-03-2009, 08:19 AM #4
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
From your description that is the behavior you would get if you do call sleep on the EDT.
Either you are mistakingly calling sleep on the EDT or you are running some long task on the EDT.Last edited by r035198x; 09-03-2009 at 08:27 AM.
- 09-15-2009, 10:55 AM #5
Member
- Join Date
- Sep 2009
- Posts
- 1
- Rep Power
- 0
This is correct and expected behavior
The thread that invokes the sleep command is the one that is put to sleep.
It does not matter on what thread u invoked the sleep method, always the calling thread goes to sleep.
Therefore, in your case the main thread itself is going to sleep.
- 10-02-2009, 12:25 PM #6
Member
- Join Date
- Sep 2009
- Posts
- 6
- Rep Power
- 0
For all intensive purposes the main thread (you only have one) is in fact the thread the UI is operating on. Calling Thread.sleep will sleep the current thread, hence the UI locking up. If you need to have independent operations taking place then you need to run them on a different thread.
- 10-02-2009, 12:41 PM #7
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
- 10-02-2009, 01:10 PM #8
Member
- Join Date
- Sep 2009
- Posts
- 6
- Rep Power
- 0
Similar Threads
-
Difference between Thread.yield() and Thread.sleep() methods
By Nageswara Rao Mothukuri in forum New To JavaReplies: 12Last Post: 07-30-2010, 05:37 PM -
thread.sleep
By jc5 in forum CLDC and MIDPReplies: 0Last Post: 09-02-2009, 11:51 PM -
Sleep in thread
By jithan in forum New To JavaReplies: 1Last Post: 08-27-2008, 02:27 PM -
Can't get my thread to sleep!
By jamesfrize in forum New To JavaReplies: 2Last Post: 03-25-2008, 05:14 AM -
How to use the sleep and thread?
By jiuhu in forum Java AppletsReplies: 4Last Post: 08-07-2007, 02:56 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks