< prev index next >

test/jdk/java/awt/Frame/NonEDT_GUI_DeadlockTest/NonEDT_GUI_Deadlock.java

Print this page




   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 
  25 /*
  26   test

  27   @bug 4828019
  28   @summary Frame/Window deadlock
  29   @author yan@sparc.spb.su: area=
  30   @run applet NonEDT_GUI_Deadlock.html
  31 */
  32 
  33 // Note there is no @ in front of test above.  This is so that the
  34 //  harness will not mistake this file as a test file.  It should
  35 //  only see the html file as a test file. (the harness runs all
  36 //  valid test files, so it would run this test twice if this file
  37 //  were valid as well as the html file.)
  38 // Also, note the area= after Your Name in the author tag.  Here, you
  39 //  should put which functional area the test falls in.  See the
  40 //  AWT-core home page -> test areas and/or -> AWT team  for a list of
  41 //  areas.
  42 // Note also the 'AutomaticAppletTest.html' in the run tag.  This should
  43 //  be changed to the name of the test.
  44 
  45 
  46 /**
  47  * NonEDT_GUI_Deadlock.java
  48  *
  49  * summary:
  50  */
  51 
  52 import java.applet.Applet;
  53 import java.awt.*;
  54 import java.awt.event.*;
  55 import java.net.*;
  56 import java.io.*;
  57 
  58 
  59 //Automated tests should run as applet tests if possible because they
  60 // get their environments cleaned up, including AWT threads, any
  61 // test created threads, and any system resources used by the test
  62 // such as file descriptors.  (This is normally not a problem as
  63 // main tests usually run in a separate VM, however on some platforms
  64 // such as the Mac, separate VMs are not possible and non-applet
  65 // tests will cause problems).  Also, you don't have to worry about
  66 // synchronisation stuff in Applet tests they way you do in main
  67 // tests...
  68 
  69 
  70 public class NonEDT_GUI_Deadlock extends Applet
  71 {
  72     //Declare things used in the test, like buttons and labels here
  73     boolean bOK = false;
  74     Thread badThread = null;
  75 
  76     public void init()
  77     {
  78     }//End  init()
  79 
  80     public void start ()
  81     {
  82         //Get things going.  Request focus, set size, et cetera
  83 
  84         setSize (200,300);
  85         setVisible(true);
  86         validate();
  87 
  88         final Frame theFrame = new Frame("Window test");
  89         theFrame.setSize(240, 200);
  90 
  91         Thread thKiller = new Thread() {
  92            public void run() {
  93               try {
  94                  Thread.sleep( 9000 );
  95               }catch( Exception ex ) {
  96               }
  97               if( !bOK ) {
  98                  // oops,
  99                  //System.out.println("Deadlock!");
 100                  Runtime.getRuntime().halt(0);
 101               }else{
 102                  //System.out.println("Passed ok.");
 103               }
 104            }
 105         };
 106         thKiller.setName("Killer thread");
 107         thKiller.start();


 147             while (true) {
 148                 if ((System.currentTimeMillis()-ts)>3000) {
 149                     this.setVisible( false );
 150                     dispose();
 151                     break;
 152                 }
 153 
 154                 toFront();
 155                 try {
 156                     Thread.sleep(80);
 157                 } catch (Exception e) {
 158                 }
 159             }
 160         }
 161     }
 162 
 163 
 164 
 165     public static void main(String args[]) {
 166        NonEDT_GUI_Deadlock imt = new NonEDT_GUI_Deadlock();
 167        imt.init();
 168        imt.start();
 169     }
 170 
 171 
 172 }// class NonEDT_GUI_Deadlock


   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 

  24 /*
  25   @test
  26   @key headful
  27   @bug 4828019
  28   @summary Frame/Window deadlock
  29   @run main/timeout=9999 NonEDT_GUI_Deadlock

  30 */
  31 




















  32 import java.awt.*;
  33 
  34 public class NonEDT_GUI_Deadlock {

















  35     boolean bOK = false;
  36     Thread badThread = null;
  37 




  38     public void start ()
  39     {






  40         final Frame theFrame = new Frame("Window test");
  41         theFrame.setSize(240, 200);
  42 
  43         Thread thKiller = new Thread() {
  44            public void run() {
  45               try {
  46                  Thread.sleep( 9000 );
  47               }catch( Exception ex ) {
  48               }
  49               if( !bOK ) {
  50                  // oops,
  51                  //System.out.println("Deadlock!");
  52                  Runtime.getRuntime().halt(0);
  53               }else{
  54                  //System.out.println("Passed ok.");
  55               }
  56            }
  57         };
  58         thKiller.setName("Killer thread");
  59         thKiller.start();


  99             while (true) {
 100                 if ((System.currentTimeMillis()-ts)>3000) {
 101                     this.setVisible( false );
 102                     dispose();
 103                     break;
 104                 }
 105 
 106                 toFront();
 107                 try {
 108                     Thread.sleep(80);
 109                 } catch (Exception e) {
 110                 }
 111             }
 112         }
 113     }
 114 
 115 
 116 
 117     public static void main(String args[]) {
 118        NonEDT_GUI_Deadlock imt = new NonEDT_GUI_Deadlock();

 119        imt.start();
 120     }
 121 
 122 
 123 }// class NonEDT_GUI_Deadlock
< prev index next >