Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: wait(); and notify();

  1. #1
    Junior Member
    Join Date
    Aug 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default wait(); and notify();

    How come my program stays in the wait(); state on line 74 and never moves on I have to manually exit the application. Here is my code
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.Arrays;
    import java.util.*;
    import java.util.concurrent.locks.*;
    import java.io.*;
    import java.util.Random;
    import java.beans.*;
    import javax.swing.border.Border;
    import javax.swing.ImageIcon;
     
    public class PatchIt extends JFrame
    {
     
       private JButton SCCM;
       private JButton Patches;
       private JButton Start;
       private JButton Exit;
       private ImageIcon logo;
       private JLabel icon;
       private JProgressBar progress = new JProgressBar();
       private int sleepTime;
       private boolean isReady = true;
       private final static Random generator = new Random();
     
       public PatchIt()
       {
          super("Patch It UP       By SrA Aaron Horan & SSgt Christopher Barrow");
                 setLayout(new FlowLayout());
     
     
          logo = new ImageIcon("bisstrip.jpg");
     
          icon = new JLabel (logo);
     
          SCCM = new JButton("SCCM");
          SCCM.setToolTipText("This button will uninstall and reinstall Configuration manager");
     
          Patches = new JButton("Patches");
     
          sleepTime = generator.nextInt( 180000 );
     
          add(SCCM, BorderLayout.NORTH);
     
          add(icon, BorderLayout.CENTER );
     
          add(Patches, BorderLayout.SOUTH);
     
     
     
     
          ButtonHandler handler = new ButtonHandler();
     
          SCCM.addActionListener(handler);
     
     
     
       }
       private class ButtonHandler implements ActionListener
    	{
    		public void actionPerformed(ActionEvent event)  
          {
             if(event.getSource() == SCCM)
             {
                synchronized(this)
                {
                   try
                   {
     
                      Process EL = Runtime.getRuntime().exec("wscript C:\\Users\\1293714939A\\Desktop\\UAC.vbs");
                         try
                         {
                               wait();
     
                         }
                         catch (InterruptedException exception )
                         {
                         }
                   }
                   catch (IOException b)
                   {
                      b.printStackTrace();
                   }
                }
                synchronized(this)
                {
                   try
                   {
                      Process B = Runtime.getRuntime().exec("wscript C:\\Users\\1293714939A\\Desktop\\calctest.vbe");
                         notify();
                   }
                   catch (IOException b)
                   {
                      b.printStackTrace();
                   }
                }
              }
            }
          }
     
       public static void main (String [] args)
       {
     
     
          PatchIt run = new PatchIt();
          run.setSize(950,780);
          run.setVisible(true);
          run.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
     
       }
     
    }
    Last edited by helloworld922; August 14th, 2013 at 05:14 PM. Reason: please use [code] tags


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: wait(); and notify();

    Please post your code in code tags.

    Empty catch() {} blocks are useless and a bad practice. Fix that.

    What is the wait() statement waiting for, and while it's waiting, what could possibly send a notify()? In other words, are multiple threads running independently, one waiting and one able to call notify()?

Similar Threads

  1. Simple multithreading using wait and notify
    By fgstat in forum What's Wrong With My Code?
    Replies: 3
    Last Post: July 27th, 2013, 02:20 AM
  2. Help wanted using wait() and notify()
    By sandramo in forum Java Theory & Questions
    Replies: 7
    Last Post: March 29th, 2013, 12:19 PM
  3. wait(), sleep() and notify()
    By evthim in forum Threads
    Replies: 3
    Last Post: October 30th, 2012, 11:37 AM
  4. How to notify() and proceed past wait()
    By kernel_klink in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 21st, 2012, 07:40 PM
  5. How to use and notify
    By Saeid in forum Threads
    Replies: 4
    Last Post: August 12th, 2010, 11:12 AM