874 Multithreading Chapter 15 139 while ( suspended[ (Web hosting uk)
874 Multithreading Chapter 15 139 while ( suspended[ index ] && 140 threads[ index ] == currentThread ) { 141 142 // Temporarily stop thread execution. Use 143 // applet as monitor. 144 RandomCharacters.this.wait(); 145 } 146 147 } // end synchronized block 148 } 149 150 // process InterruptedExceptions during sleep or wait 151 catch ( InterruptedException interruptedException ) { 152 System.err.println( “sleep interrupted” ); 153 } 154 155 // display character on corresponding label 156 SwingUtilities.invokeLater( 157 158 // anonymous inner class used by SwingUtilities 159 // method invokeLater to ensure GUI 160 // updates properly 161 new Runnable() { 162 163 // updates Swing GUI component 164 public void run() 165 { 166 // pick random character 167 char displayChar = alphabet.charAt( 168 ( int ) ( Math.random() * 26 ) ); 169 170 outputs[ index ].setText( 171 currentThread.getName() + “: ” + 172 displayChar ); 173 } 174 175 } // end anonymous inner class 176 177 ); // end call to SwingUtilities.invokeLater 178 179 } // end while 180 181 System.err.println( 182 currentThread.getName() + ” terminating” ); 183 } 184 185 } // end private inner class RunnableObject 186 187 } // end class RandomCharacters Fig. 15.17 Demonstrating the Runnableinterface, suspending threads and resuming threads (part 4 of 5).
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.