home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 14 / IOPROG_14.ISO / soft / sdkjava / sdkjava.exe / SDKJava.cab / Samples / native_raw / java / JThread1.java < prev    next >
Encoding:
Java Source  |  1998-03-05  |  1.5 KB  |  67 lines

  1. // Copyright (c) 1996-1998 Microsoft Corporation.  All rights reserved.
  2. ////////////////////////////////////////////////////////////////////////////////
  3. //
  4. //    JThread1
  5. //
  6. //    runs with JThread2;  this can be considered the master thread i.e.
  7. //    JThread2 will block on this thread, until we pulse the passed event
  8. //    sync object.
  9. //
  10. ////
  11. public class JThread1 implements Runnable
  12. {
  13.     int    m_SleepMillis ;
  14.     int    m_hEvent ;
  15.  
  16.     ////////////////////////////////////////////////////////////////////////
  17.     //
  18.     //    JThread1()
  19.     //
  20.     //    constructor; sets our event sync object and the time to sleep
  21.     //    prior to pulsing the object.
  22.     //
  23.     ////
  24.     JThread1(int iSleepMillis, int hEvent)
  25.     {
  26.         m_SleepMillis = iSleepMillis ;
  27.         m_hEvent = hEvent ;
  28.     }
  29.  
  30.     ////////////////////////////////////////////////////////////////////////
  31.     //
  32.     //    natively implemented method (see ..\native\natlib.c for
  33.     //    details)
  34.     //
  35.     //        w32PulseEvent()
  36.     //
  37.     ////
  38.     public native void w32PulseEvent(int hEvent) ;
  39.  
  40.     ////////////////////////////////////////////////////////////////////////
  41.     //
  42.     //    run()
  43.     //
  44.     //    thread runs on this method; we sleep for specified time then
  45.     //    pulse the event object (resuming JThread2 object); banners
  46.     //    display progress.
  47.     //
  48.     ////
  49.     public synchronized void run()
  50.     {
  51.         // sleep
  52.         try { Thread.sleep(m_SleepMillis) ; }
  53.         catch (Exception e)
  54.         {
  55.             e.printStackTrace() ;
  56.         }
  57.  
  58.         System.out.println("JThread1: calling w32PulseEvent()") ;
  59.  
  60.         // pulse the object
  61.         w32PulseEvent(m_hEvent) ;
  62.  
  63.         System.out.println("JThread1 completing") ;
  64.     }
  65. }
  66.  
  67.