home *** CD-ROM | disk | FTP | other *** search
/ Chip Special: HTML & Java / Chip-Special_1997-01_HTML-a-Java.bin / javasdk / sdk-java.exe / SDKJava.cab / Samples / native_raw / java / JThread1.java < prev    next >
Encoding:
Java Source  |  1996-10-10  |  1.5 KB  |  72 lines

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