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

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