1
00:00:00,004 --> 00:00:04,002
- [Narrator] Java Nine includes
updates to the Process API.

2
00:00:04,002 --> 00:00:06,006
The Process API controls and manages

3
00:00:06,006 --> 00:00:09,001
operating system processes.

4
00:00:09,001 --> 00:00:11,002
The old version frequently
caused programmers

5
00:00:11,002 --> 00:00:13,003
to use native code to work around

6
00:00:13,003 --> 00:00:15,005
the limitations of the API.

7
00:00:15,005 --> 00:00:17,000
Prior to this release,

8
00:00:17,000 --> 00:00:19,008
there was a limited ability
for controlling and managing

9
00:00:19,008 --> 00:00:22,002
operating system processes with Java.

10
00:00:22,002 --> 00:00:25,000
For example, in order to
do something as simple

11
00:00:25,000 --> 00:00:27,009
as get your Process I.D., the PID,

12
00:00:27,009 --> 00:00:29,007
in earlier versions of Java,

13
00:00:29,007 --> 00:00:31,007
you would need to either
access native code

14
00:00:31,007 --> 00:00:34,003
or use some other workaround.

15
00:00:34,003 --> 00:00:36,001
One other problem is that it would require

16
00:00:36,001 --> 00:00:38,009
a different implementation
for each platform,

17
00:00:38,009 --> 00:00:41,002
to make sure you're
getting the right result.

18
00:00:41,002 --> 00:00:43,007
This new update extends Java's ability

19
00:00:43,007 --> 00:00:46,002
to interact with the operating system.

20
00:00:46,002 --> 00:00:49,001
New, direct methods
are available to handle

21
00:00:49,001 --> 00:00:52,005
the Process IDs, process names and states,

22
00:00:52,005 --> 00:00:56,001
and the ability to enumerate
the Java virtual machines

23
00:00:56,001 --> 00:00:59,000
and processes, and more.

24
00:00:59,000 --> 00:01:02,004
This update includes
a ProcessHandle class,

25
00:01:02,004 --> 00:01:05,003
which provides access to critical data.

26
00:01:05,003 --> 00:01:08,002
Examples of that critical data include:

27
00:01:08,002 --> 00:01:11,000
the native process ID, the PID,

28
00:01:11,000 --> 00:01:14,001
arguments, the command that was used,

29
00:01:14,001 --> 00:01:15,002
the start time,

30
00:01:15,002 --> 00:01:17,005
the accumulated CPU time,

31
00:01:17,005 --> 00:01:19,001
who was the user,

32
00:01:19,001 --> 00:01:20,008
what was the parent process,

33
00:01:20,008 --> 00:01:23,000
and who are the descendants.

34
00:01:23,000 --> 00:01:25,009
Updates for the process API enable

35
00:01:25,009 --> 00:01:28,009
getting the process ID of
the current JVM process,

36
00:01:28,009 --> 00:01:32,005
enumerate processes running in the system,

37
00:01:32,005 --> 00:01:38,001
manage process trees,
and manage subprocesses.

38
00:01:38,001 --> 00:01:40,001
Here is a sample code snippet

39
00:01:40,001 --> 00:01:43,004
that uses the new ProcessHandle class.

40
00:01:43,004 --> 00:01:45,008
As you can see, inside static void main

41
00:01:45,008 --> 00:01:49,003
we're declaring a new
variable called currentProcess

42
00:01:49,003 --> 00:01:52,005
that is of type ProcessHandle.

43
00:01:52,005 --> 00:01:55,000
We use that to get the PID.

44
00:01:55,000 --> 00:01:59,002
So we print that out, then
we use the ProcessHandle.Info

45
00:01:59,002 --> 00:02:02,006
and create another variable
called currentProcessInfo,

46
00:02:02,006 --> 00:02:06,005
and then we print out the
current process information.

47
00:02:06,005 --> 00:02:10,006
This new API makes getting
that information much easier.

