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 / JThread2.java < prev    next >
Encoding:
Java Source  |  1996-10-10  |  1.4 KB  |  64 lines

  1. /*
  2.  
  3. Copyright (c) 1996  Microsoft Corporation
  4.  
  5. */
  6.  
  7. ////////////////////////////////////////////////////////////////////////////////
  8. //
  9. //    JThread2
  10. //
  11. //    thread runs on this to demonstrate GC-awareness in native code.
  12. //
  13. ////
  14.  
  15. public class JThread2 implements Runnable
  16. {
  17.     int    m_hEvent ;
  18.  
  19.     ////////////////////////////////////////////////////////////////////////
  20.     //
  21.     //    JThread2()
  22.     //
  23.     //    constructor; sets our handle to the event object, which will
  24.     //    be used for synchronization in native code.
  25.     //
  26.     ////
  27.     JThread2(int hEvent)
  28.     {
  29.         m_hEvent = hEvent ;
  30.     }
  31.  
  32.     ////////////////////////////////////////////////////////////////////////
  33.     //
  34.     //    natively implemented methods (see ..\native\natlib.c for
  35.     //    details)
  36.     //
  37.     //        GCSafeNative()
  38.     //        w32CloseHandle()
  39.     //
  40.     ////
  41.     public native void GCSafeNative(int hEvent) ;
  42.     public native int w32CloseHandle(int hObject) ;
  43.  
  44.     ////////////////////////////////////////////////////////////////////////
  45.     //
  46.     //    Thread runs on this method; show banners to display progress
  47.     //
  48.     ////
  49.     public synchronized void run()
  50.     {
  51.         System.out.println("JThread2 calling GCSafeNative()") ;
  52.  
  53.         // call out to native code
  54.         GCSafeNative(m_hEvent) ;
  55.  
  56.         // in this case, we know we're the last to use hEvent, so
  57.         //  we close it prior to exit.
  58.         w32CloseHandle(m_hEvent) ;
  59.  
  60.         System.out.println("JThread2 completing") ;
  61.     }
  62. }
  63.  
  64.