?
Solved

Threads, systems keeps getting frozen

Posted on 2003-03-27
13
Medium Priority
?
166 Views
Last Modified: 2010-03-31
I got a GUI, and when i call the sleep thread method, it keeps freezing the GUI and i cnt use it during that time. and i need to be able to :(

this is the method i am calling :

-------------

 public void runnable(String delay) {
          int count = 0;
          int time = 0;
           time = Integer.parseInt(delay);
          while (count < time) {
              try {
                 Thread.sleep(1000);
             } catch (InterruptedException e) { }
            count++;
        }
               stop();
    }    
-----------------------
0
Comment
Question by:mkrashid
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +5
13 Comments
 
LVL 1

Expert Comment

by:pronane
ID: 8219302
what is time set as?? the thread may be sleeping to long.
0
 

Author Comment

by:mkrashid
ID: 8219357
time is set as like e.g 2,5,6 thats how many seconds i want it to sleep for, it sleeps for the right amound of time, as i did a system.out.printlin and it works ok, its just that during this, it freezes up the GUI, and i cnt do nothing else.
0
 
LVL 1

Expert Comment

by:pronane
ID: 8219387
what do you want to sleep?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 35

Expert Comment

by:girionis
ID: 8219388
 What happens if you add Thread.yield(); in the while loop? The GUI functionality is taking place in another thread and it could be waiting for the main thread to finish.
0
 
LVL 1

Expert Comment

by:pronane
ID: 8219433
yes exactly and thats why its freezing cos the thread is sleeping and the gui is waiting for it to finish.
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 200 total points
ID: 8219968
You shouldn't be sleeping the GUI thread normally. If you want to do whatever that code is doing you posted, use a separate thread.
0
 
LVL 3

Expert Comment

by:wide_awake
ID: 8220315
You could try using the Timer class instead of using Thread.sleep()

0
 

Author Comment

by:mkrashid
ID: 8221020
i am reading a dat file and the numbers which are read in are converted from string to int and placed in 'time' which determines how long the thread should sleep for, but i want the rest of the gui to bbe active, i am new to threads and if possible could sumone show code example please  
0
 
LVL 3

Expert Comment

by:wide_awake
ID: 8221275
Either a thread is asleep, or it is active.  It can't be both.

If you want something to happen after X seconds, then an instance of Timer will do just that.

from the api docs:

  int delay = 1000; //milliseconds
  ActionListener taskPerformer = new ActionListener()
  {
      public void actionPerformed(ActionEvent evt)
      {
          //...Perform a task...
      }
  };
  new Timer(delay, taskPerformer).start();

0
 
LVL 92

Expert Comment

by:objects
ID: 8221487
All GUI processing is handled in a single thread. If you block that thread (using sleep() for instance) then your GUI will freeze.
You need to do your processing in a seperate thread as suggested by CEHJ.
0
 

Expert Comment

by:CleanupPing
ID: 9058451
mkrashid:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9734925
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept CEHJ's comment as answer.

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jimmack
EE Cleanup Volunteer
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses
Course of the Month8 days, 18 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question