Runtime¶
Каждое Java-приложение имеет один экземпляр класса Runtime, который позволяет приложению взаимодействовать со средой, в которой выполняется приложение.
getRuntime()Returns the Runtime object associated with the current Java application.
Ссылки:
Получение текущих характеристик¶
availableProcessors()Returns (int) the number of processors available to the Java virtual machine.
freeMemory()Returns (long) the amount of free memory in the Java Virtual Machine.
maxMemory()Returns (long) the maximum amount of memory that the Java virtual machine will attempt to use.
totalMemory()Returns (long) the total amount of memory in the Java virtual machine.
Управление состоянием JVM¶
Прерывание процесса исполнения:
exit(int status)Terminates the currently running Java virtual machine by initiating its shutdown sequence.
halt(int status)Forcibly terminates the currently running Java virtual machine. This method never returns normally.
В отличие от метода выхода, этот метод не приводит к запуску Shutdown hook и не запускает непроверенные finalizators, если включена финализация при выходе.
Shutdown hook:
A shutdown hook is simply an initialized but unstarted thread. When the virtual machine begins its shutdown sequence it will start all registered shutdown hooks in some unspecified order and let them run concurrently.
When all the hooks have finished it will then run all uninvoked finalizers if finalization-on-exit has been enabled.
Finally, the virtual machine will halt.
Note
Daemon потоки будут продолжать работать во время shutdown последовательности.
Так же как и non-daemon потоки, если завершение работы было инициировано путем вызова exit() метода.
addShutdownHook(Thread hook)Registers a new virtual-machine shutdown hook.
hook- An initialized but unstarted Thread object.removeShutdownHook(Thread hook)De-registers a previously-registered virtual-machine shutdown hook. Returns boolean.
Управление GC:
gc()Runs the garbage collector.
runFinalization()Runs the finalization methods of any objects pending finalization.
Запуск сторонних процессов¶
exec(String command): ProcessExecutes the specified string command in a separate process.
exec(String[] cmdarray): ProcessExecutes the specified command and arguments in a separate process.
exec(String[] cmdarray, String[] envp): ProcessExecutes the specified command and arguments in a separate process with the specified environment.
exec(String[] cmdarray, String[] envp, File dir): ProcessExecutes the specified command and arguments in a separate process with the specified environment and working directory.
exec(String command, String[] envp): ProcessExecutes the specified string command in a separate process with the specified environment.
exec(String command, String[] envp, File dir): ProcessExecutes the specified string command in a separate process with the specified environment and working directory.
Загрузка динамических библиотек¶
load(String filename)Loads the specified filename as a dynamic library.
loadLibrary(String libname)Loads the dynamic library with the specified library name.