1 /* 2 * Copyright (C) 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 public class Main { 18 19 private static class Child implements Runnable { 20 @Override run()21 public void run() { 22 System.out.println("Child started"); 23 // Enter native method and stay there, monitoring shutdown behavior. Since we're a daemon, 24 // the process should shut down anyway, and we should be able to observe changes in the 25 // extended JNI environment. 26 monitorShutdown(); 27 } 28 } 29 main(String[] args)30 public static void main(String[] args) { 31 System.loadLibrary(args[0]); 32 System.out.println("Main Started"); 33 Thread t = new Thread(new Child()); 34 t.setDaemon(true); 35 t.start(); 36 try { 37 Thread.sleep(400); 38 } catch (InterruptedException e) { 39 System.out.println("Unexpected interrupt"); 40 } 41 System.out.println("Main Finished"); 42 } 43 monitorShutdown()44 private static native void monitorShutdown(); 45 } 46