Why myThread.sleep(60000) Hangs Computer?

I have been battling a thread hanging problem in my application for several days now. It appears to be hanging when I tell my second thread to sleep, but not
all the time -- only after about four hours of running does it hang. The application is like a timer/scheduler. You tell it when you want to be notified, say in 60 minutes. It wakes up every 1 minute, updates the progress bars, then goes back to sleep, until 60 minutes has passed... But like I said, on some of the sleeps, it's not waking up. Below is the code that I think is significant...
public class Timer extends JApplet implements Runnable, ActionListener {
* Listens to the user interface buttons for this dialog.
* @param e The action event.
public void actionPerformed(ActionEvent e) {
JButton source = (JButton)e.getSource();
if (source.getActionCommand().equals("Start")) {
timerThread = new Thread(this, "Timer");
timerThread.setPriority(Thread.MIN_PRIORITY);
timerThread.start();
* Start timing the scheduled events.
public void run() {
boolean interrupted = false;
boolean firstTask = true;
while(!interrupted) {
interrupted = !runTask (
"Meal 1", this.mealTimeField0, mealBeginClip, mealEndClip);
interrupted = !runTask(
"Work 1", this.workTimeField0, workBeginClip, workEndClip);
interrupted = !runTask (
"Rest 1", this.restTimeField0,restBeginClip, restEndClip);
//more of the same
interrupted = !runTask (
"Sleep", this.sleepTimeField, sleepBeginClip, sleepEndClip);
private boolean runTask (
String barText, JTextField field, AudioClip beginClip, AudioClip endClip) {
try {
int minutes = stringToPosInt (field.getText());
timerThread.sleep(60 * 1000);
for (int i = 1; i < minutes; ++i) {
System.out.println("before sleep");
timerThread.sleep(60 * 1000); //hangs here??????
System.out.println("after sleep");
} catch (InterruptedException e) {return false;}
return true;
}

When it skips some of the sleeps, does it later wake up again? I'm wondering if it is waking up on some multiple of the sleep period. Apart from the wording of the api docs, I'm not sure if Sun intended to guarantee that sleep would wake up immediately on the specified time. They've always been pretty vague about the required semantics on the implementations of threads in any JVM. I'd guess that something else is going on at the time your thread was due to wake up, like something on the AWT thread, and the thread is getting skipped until the next iteration. Wierd, but its all I can think of.
Try substituting wait(60*1000) for sleep(60*1000).
Also, two other suggestions. Read the "special token" information on this site so that your code will be formatted nicely in the message; makes it easier for others to understand what it does. Also, sleep is a static method, so keep in mind that timerThread.sleep will put the current thread to sleep, whatever that may be. That means you have to be careful not to execute something like that in a method that will be executed by the AWT thread; it won't do what you expected it to do.

Similar Messages

  • Why is MAX crashing my computer?

    when I run the resource monitor in MAX my computer is locking up at the "configuring mainframe 1" stage.  The set up is a pci-mxi-2 to vme-mxi-2.  Do you have any idea what could be causing the computer to hang up like this?

    Hi,
    There is a great Knowledge Base on why Resource Manager might hang. Please follow this link to view it and let me know if this helps you.
    Regards
    Krista S.
    Applications Engineering
    National Instruments

  • Why does my iTunes hang every time when using automatic device detect?

    Why does my iTunes hang every time that I connect either of my devices (iTouch-4th Gen, iPod Nano-5th Gen), to my Win 7 (64-bit) PC desktop?  By the way, this does not happen if I open iTunes first, and then connect the device.  So my workaround was to simply uncheck the checkbox that allows iTunes to start automatically upon device connection.  This doesn't fix the problem, but it allows me to synch my device, but it would be nice to be able to have the autodetect work properly, so that iTunes would start normally without locking up on me and freezing. That's what I mean by 'hanging'.  My whole computer doesn't freeze--only iTunes.

    Hello E
    Start with finding the path where the songs are on your PC by right clicking the songs that are missing in iTunes and click Get Info. You should get a window that pops up and in the Summary tab; the path will be there. Then navigate to where it was and see if the files exist. Other than that you can try to search your computer to find those files. Checkout the articles below for tips on finding the missing music, also if some of the tracks are downloaded from the iTunes Store you can download the tracks again by deleting the missing tracks from iTunes and then navigating to the purchases section in the iTunes Store to download them again.
    iTunes: Finding lost media and downloads
    http://support.apple.com/kb/TS1408
    Download past purchases
    http://support.apple.com/kb/HT2519
    Regards,
    -Norm G.

  • Why does my iPad hang when writing an email?  When I'm done with the email, I can't send it out and have to re-boot the iPad.

    Why does my iPad hang when writing an email?  When I'm done with the email, I can't send it out and have to re-boot the iPad. This happens if the time to compose email exceeds 10 to 15 minutes.

    Shut down all programs that are running in the background.
    1. Double-click the Home button to see Apps in background
    2. Hold the Apps down for a second or two until you see the minus sign
    3. Tap the minus sign to close program
    4. Reset iPad. Hold the Sleep and Home button down for about 10 second until you see the Apple logo
    Suggest you perform Step 1 to 3 at the end of every day.

  • My password works fine when I turn the computer on, but when I try to wake it from sleep mode the computer doesn't recognize my password -- the same one I used successfully when I turned the computer on.

    My password works fine when I turn the computer on, but when I try to wake it from sleep mode the computer doesn't recognize my password -- the same one I used successfully when I turned the computer on.

    Okay, I seem to have solved the problem I posted about earlier.  I noticed that the language preference in the upper right hand corner of the screen (between the date and time and the Spotlight icon) had somehow gotten switched from American English to French.  When I switched it back to American English, my password worked when waking the computer from sleep mode.  I have no idea why changing the language preference would affect the way the password works but that seems to have been the case.  I'll post again if I experience more problems.

  • Why are my apps hanging when i try and update them? i have the iphone 4 with the new ios 6....

    Why are my Apps hanging and not letting me update them on my phone? the app store has been really slow, and tells me alot of the times that it is unable to connect with the store? I am frustrated and don't know what to do....

    I am trying to do that now but with my computer, this problem is happening as well.... I am able to download a select few of the updates....

  • Why does my system hang on a blank software update screen after I shut down?

    Why does my system hang on a blank software update screen after I shut down the computer?
    This only happened after my computer attempted to download security update 2013-003 version 1.
    I have an iMac with a 2.16 GHz Intel Core 2 Duo running on OSX 10.7.5.
    I repaired all disk permission, and then verified and fixed the disk.
    My hardware diagnostics program gave all systems a green light.
    After all this, the system still hangs.
    This must be an operating system glitch.
    How do I fix it?
    If you tell me to reload the operating system, then I'll have to go retro with Snow Leopard.
    All subsequent updates were purchased from Apple on the Internet and downloaded.

    Cineast wrote:
    If you tell me to reload the operating system, then I'll have to go retro with Snow Leopard.
    All subsequent updates were purchased from Apple on the Internet and downloaded.
    Not so. You use the recovery mode to reinstall Lion. Details in Recovery and About OS X Recovery. Also, see Computers using Internet Recovery.

  • (early 2014) rMBP abruptly goes black (sleep mode) when computer is tilted at certain angles or lifted.

    My (early 2014) rMBP abruptly goes black (sleep mode) when computer is tilted at certain angles or lifted. Ive reset Energy saver mode to factory defaults and the problem still occurs.

    Please make a Genius Appointment and take it in for service.

  • Why is my applet hanging?

    Can anyone give me some insight as to why my applet is hanging? I just get the grey rectangle and no output in the java plugin console as to any kind of errors. I think it may have to do with hte ContentPane in both the main() and init() but I am not sure. I have been struggling with this problem for a couple of days now and I am not sure how to resolve it. Thanks in advance
    import java.awt.*;
    import java.lang.*;
    import java.io.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.filechooser.*;
    import javax.swing.event.*;
    import javax.swing.border.*;
    import java.awt.image.*;
    import javax.swing.text.*;
    import com.tpg.base.MileMessages;
    public class BlackBoxUIApplet extends JApplet implements ActionListener{
         public static int WIDTH = 800;
         public static int HEIGHT = 450;
         private boolean inAnApplet = true;
         //public static String TITLE = "Turnpike BlackBoxUI";
         //public static String input;
         Container frameContainer;
         JPanel[] panels = new JPanel[4];
         JMenuBar menuBar = new JMenuBar();
         JMenu fileMenu = new JMenu("File");
         JMenuItem fileExit = new JMenuItem("Exit");
         //Icon openIcon = new ImageIcon("C:\\Dave\\Java Swing\\open.gif");
         JLabel statusLabel = new JLabel();
         //Icon statusIcon = new ImageIcon("flashing_red_button.gif");
         JButton pushButton1 = new JButton("Process File");
         JButton pushButton2 = new JButton("Process Folder");
         JButton pushButton3 = new JButton("One More Button");
         JButton openButton = new JButton("Open a File");
         //JLabel pbLabel = new JLabel("Processing.....");
         JTextArea textArea = new JTextArea(30,90); //rows,cols
         JScrollPane areaScrollPane = new JScrollPane(textArea);          
         JTextField inputFile = new JTextField(32);
         JTextField status = new JTextField(20);
         JTextField status1 = new JTextField(20);
         //JProgressBar pb = new JProgressBar();
         PipedInputStream piOut;
    PipedOutputStream poOut;
         String inputValue;
         MileMessages messages;
         //pb.setIndeterminate(true);
         //to avoid message about system event access
         public BlackBoxUIApplet() throws IOException
              this(true);
         //public BlackBoxUIApplet(boolean inAnApplet)
         public BlackBoxUIApplet(boolean inAnApplet) throws IOException
         //super(TITLE);
         //input = inputValue;
         this.inAnApplet = inAnApplet;
              if(inAnApplet)
                   getRootPane().putClientProperty("defeatSystemEventQueueCheck",
                                                                                              Boolean.TRUE);
                   // Set up System.out
    piOut = new PipedInputStream();
    poOut = new PipedOutputStream(piOut);
                        messages = new MileMessages();
    System.setOut(new PrintStream(poOut, true));
                        // Create reader threads
    new ReaderThread(piOut).start();
         public void init()
         setContentPane(buildGUI());
         //addWindowListener(new WindowHandler());
         fileExit.addActionListener(new MenuItemHandler());
         pushButton1.addActionListener(this);
         pushButton2.addActionListener(this);
         pushButton3.addActionListener(this);
         openButton.addActionListener(this);
         //setupEventHandlers();
         setSize(WIDTH, HEIGHT);
         setBackground(Color.darkGray);
         inputValue = JOptionPane.showInputDialog("Please input your ctxURL: (eg. //localhost:8080/main/InboundXMLServlet)");
         messages.runMilesMessages(inputValue);
         //show();
         public void actionPerformed(ActionEvent e)
              String cmd = e.getActionCommand();
              System.out.println("Command is: " + cmd);
              if(cmd.equals("Process File"))
                   textArea.append("I am processing!" + "\n");
                   System.out.println("ctxURL is: " + inputValue);
                   //status.setText("Currently processing " + inputValue + "....");
              else if(cmd.equals("Open a File"))
                        //final JFileChooser fc = new JFileChooser(new File(System.getProperty("user.dir"))); //goes up two levels from invoking directory
                        //final JFileChooser fc = new JFileChooser("../.."); //goes up two levels from invoking directory
                        final JFileChooser fc = new JFileChooser("../..");
                        fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
                        int returnVal = fc.showOpenDialog(this);
                        if (returnVal == JFileChooser.APPROVE_OPTION)
                             File file = fc.getSelectedFile();
                             inputFile.setText(file.getPath());
              else if(cmd.equals("Process Folder"))
              else if(cmd.equals("One More Button"))
         public Container buildGUI()
              setupMenuBar();
              Container tempContainer = layoutComponents();
              return (tempContainer);
         void setupMenuBar()
              fileMenu.add(fileExit);
              menuBar.add(fileMenu);
              setJMenuBar(menuBar);
         public Container layoutComponents()
              for(int i=0; i<panels.length;++i)
                   panels[i] = new JPanel();
                   panels[0].setBorder(new TitledBorder("Push Buttons"));
                   //panels[0].setBorder(BorderFactory.createEtchedBorder());
                   panels[0].setLayout(new FlowLayout(1, 10, 90)); //center with horz gap of 10 and vert gap of 60
                   //panels[0].setLayout(new BorderLayout());
                   //panels[0].setLayout(new GridLayout(3,1));
                   //use setPreferredSize(Dimension) to change size of each panel
                   //panels[0].setAlignmentX((float) 20);
                   pushButton1.setMargin(new Insets(5,10,5,10));
                   pushButton1.setVerticalTextPosition(AbstractButton.CENTER);
                   pushButton1.setHorizontalTextPosition(AbstractButton.LEFT);
                   pushButton1.setToolTipText("Process a File");
                   pushButton2.setMargin(new Insets(5,10,5,10));
                   pushButton2.setVerticalTextPosition(AbstractButton.CENTER);
                   pushButton2.setHorizontalTextPosition(AbstractButton.LEFT);
                   pushButton2.setToolTipText("Process a Folder");
                   pushButton3.setMargin(new Insets(5,10,5,10));
                   pushButton3.setVerticalTextPosition(AbstractButton.CENTER);
                   pushButton3.setHorizontalTextPosition(AbstractButton.LEFT);
                   pushButton3.setToolTipText("Tip3");
                   //panels[0].add(Box.createVerticalStrut(2));
                   panels[0].add(pushButton1);
                   //panels[0].add(pushButton1, BorderLayout.NORTH);
                   //panels[0].add(Box.createVerticalStrut(2));
                   panels[0].add(pushButton2);
                   //panels[0].add(pushButton2, BorderLayout.CENTER);
                   //panels[0].add(Box.createVerticalStrut(2));
                   panels[0].add(pushButton3);
                   //panels[0].add(pushButton3, BorderLayout.SOUTH);
                   panels[1].setBorder(new TitledBorder("Status"));
                   panels[1].setLayout(new FlowLayout(1,10,60));
                   //panels[1].setBorder(BorderFactory.createEtchedBorder());
                   //panels[1].setLayout(new GridLayout(2,1));
                   status.setEditable(false);
                   status1.setEditable(false);
                   //statusLabel.setIcon(statusIcon);
                   panels[1].add(statusLabel);
                   status.setText("Server is OK.");
                   status1.setText("File is OK.");
                   panels[1].add(status);
                   panels[1].add(status1);
                   //panels[1].add(pbLabel);
                   //pb.setIndeterminate(true);
                   //panels[1].add(pb);
                   //pb.setValue(0);
                   //pb.setStringPainted(true);
                   panels[2].setBorder(new TitledBorder("File Input"));
                   //panels[2].setBorder(BorderFactory.createEtchedBorder());
                   //panels[2].setLayout(new BoxLayout(panels[2], BoxLayout.X_AXIS));
                   panels[2].setLayout(new FlowLayout(1,50,20));
                   //panels[2].setLayout(new GridLayout(1,2));
                   //panels[2].add(Box.createHorizontalStrut(5));
                   panels[2].add(inputFile);
                   //panels[2].add(Box.createVerticalStrut(5));
                   panels[2].add(openButton);
                   //panels[2].add(Box.createHorizontalStrut(15));
                   panels[3].setBorder(new TitledBorder("Output"));
                   //panels[3].setBorder(BorderFactory.createEtchedBorder());
                   panels[3].setLayout(new GridLayout(1,1));
                   textArea.setFont(new Font("Serif", Font.PLAIN, 16));
                   textArea.setMargin(new Insets(5,5,5,5));
                   textArea.setLineWrap(true);
                   textArea.setWrapStyleWord(true);
                   textArea.setEditable(false);
                   areaScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
                   areaScrollPane.setPreferredSize(new Dimension(50, 50));
                   panels[3].add(areaScrollPane);
                   frameContainer = getContentPane();
                   frameContainer.setLayout(new GridLayout(2,2));
                   //frameContainer.setLayout(new FlowLayout());
                   for(int i=0;i<panels.length;++i)
                        frameContainer.add(panels);
                        //frameContainer.add(Box.createHorizontalStrut(5));
                   return (frameContainer);
         //void setupEventHandlers()
              //addWindowListener(new WindowHandler());
              //fileExit.addActionListener(new MenuItemHandler());
              //pushButton1.addActionListener(new ButtonHandler());
              //pushButton2.addActionListener(new ButtonHandler());
              //pushButton3.addActionListener(new ButtonHandler());
              //openButton.addActionListener(new OpenHandler());
              //inputFile.setActionCommand(textFieldString);
              //inputFile.addActionListener(new TextHandler());
              //cmdField.addAncestorActionListener(new TextAreaHandler());
              //status.addAncestorActionListener(new TextAreaHandler());
         public static void main(String[] args)
              JFrame frame = new JFrame();
              frame.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
              try
                   BlackBoxUIApplet app = new BlackBoxUIApplet(true);
              frame.setContentPane(app.buildGUI());
              frame.pack();
              frame.setVisible(true);
              catch (IOException e)
         public class MenuItemHandler implements ActionListener
              public void actionPerformed(ActionEvent e)
                   String cmd = e.getActionCommand();
                   if(cmd.equals("Exit")) System.exit(0);
         class ReaderThread extends Thread {
    PipedInputStream pi;
    ReaderThread(PipedInputStream pi) {
    this.pi = pi;
    public void run() {
    final byte[] buf = new byte[1024];
    try {
    while (true) {
    final int len = pi.read(buf);
    if (len == -1) {
    break;
    SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    textArea.append(new String(buf, 0, len));
    // Make sure the last line is always visible
    textArea.setCaretPosition(textArea.getDocument().getLength());
    // Keep the text area down to a certain character size
    int idealSize = 100000;
    int maxExcess = 500;
    int excess = textArea.getDocument().getLength() - idealSize;
    if (excess >= maxExcess) {
    textArea.replaceRange("", 0, excess);
    } catch (IOException e) {

    I think I figured out why the applet is hanging. It is right after I call messages.MileMessage(inputValue). That method search the drive for a certain file type. the only problem is that I want to repaint the applet after that method is called and I don't understand how the method is called before I input hte "inputValue" variable! Is there any way to stall the method call until after everything is painted and the inputValue is entered? Sorry, but you hve to look to the previous post for the code.
    -Dave

  • TS4502 why i cannot connect from computer to my ipad

    why i cannot connect from computer to my ipad

    you need to install latests version of itunes on the computer

  • Why is Lightroom 5 hanging when trying to export images?

    Why is Lightroom 5 hanging when trying to export images?

    I've been having the same issues, mainly with videos.  Any resolution to your issue yet?

  • Why won't my iMac computer let me find a driver to install my HP eprint D110a series?

    Why won't my iMac computer let me find a driver to install my HP eprint D110a series? I'm new at this so please bare with me here... lol... Thank you..

    Hi,
    Hey that's a good sytem as well as the print, please click the following link to download the drivers.
    http://h10025.www1.hp.com/ewfrf/wc/softwareDownloadIndex?softwareitem=mp-80514-1&lc=en&dlc=en&cc=us&...
    Thanks
    Josh.C
    Click on the BLUE KUDOS button on the left to say "Thanks"
    Although I am an HP employee, I am speaking for myself and not for HP.

  • Why do I get a "computer not authorized message" when it is authorized?

    Does anyone know why do I get a "computer not authorized message" when it is authorized and how to fix the problem?  I downloaded a couple of new apps on my iPhone and these wont sych with my iMac

    i have the same problem but i have not found a way to fix it

  • Why does firefox 4 hang in some websites, during browsing on that site ? This never happened with previous editions.

    why does firefox 4 hang in some websites, during browsing on that site ? This never happened with previous editions. edit
    Details

    Start Firefox in [[Safe Mode]] to check if one of the add-ons is causing the problem (switch to the DEFAULT theme: Tools > Add-ons > Themes).
    * Don't make any changes on the Safe mode start window.
    See:
    * [[Troubleshooting extensions and themes]]
    Create a new profile as a test to check if your current profile is causing the problems.<br />
    See [[Basic Troubleshooting#Make_a_new_profile|Basic Troubleshooting&#58; Make a new profile]]<br />
    There may be extensions and plugins installed by default in a new profile, so check that in "Tools > Add-ons > Extensions & Plugins"<br />
    If that new profile works then you can transfer some files from the old profile to that new profile (be careful not to copy corrupted files)
    See http://kb.mozillazine.org/Transferring_data_to_a_new_profile_-_Firefox

  • Why does Firefox keep hanging, crashing, sulking, dying when internet connection behaves?

    Why does Firefox keep hanging, crashing, sulking, dying when internet connection behaves? Once it renders the page it should forget about the page. Why does it behave when some link is clicked when there is no internet? It should just say internet not available or some crap. Why die, sulk, crash?? I don't get it! 3 series was much much much better!

    I should add, I've re-downloaded Firefox, but that doesn't look like it has helped any. Still get seemingly inexplicable crashes.

Maybe you are looking for

  • Is Adobe Lightroom or Adobe Elements better?

    Hi, I am testing out a free trial of Adobe Lightroom and I am attempting to figure out if it is too advanced of a program for my purposes. I have MANY, MANY images on a server, and when I want to organize these images into different categories, I hav

  • 1920x816 circles

    Hi- I have a motion project that's 1920x816 with some circles that originate from a Photoshop file. When I import this into FCP in a sequence it looks fine. I then send it to Compressor using the custom 16:9 setting under frame size, and when I enter

  • Preview Build failed to download 0x80246018

    Running Windows Technical Preview for Enterprise Build 9841.  After I enabled the Preview Builds option in Update and Recovery, I attempted to download Build 9860 but received the error "Failed to download the new preview build, please try again lat

  • Does B2B support these transactions

    We want to implement following Rosettanet transactions in b2b: 1- 3A4 -PO confirmation (inbound/outbound) 2-3A8 PO change( inbound/outbound) Does B2B supports these transactions? Regards, Sri

  • Usb guitar cable + backing track mixing.

    I'm trying to do the following with little success so far: A sample test case: Input: electric bass plugged into via usb cable (shows up as C-Media USB headphone set) youtube video (via firefox, etc) or any sound file (via moc, etc). Output: headphon