jdk/src/java.base/share/classes/java/lang/ProcessHandle.java
changeset 31681 e9a9d5b369bc
parent 31061 fead7d86d75f
child 32209 24bb680a1609
equal deleted inserted replaced
31648:59d3491e3669 31681:e9a9d5b369bc
    76  * In the case where ProcessHandles cannot be supported then the factory
    76  * In the case where ProcessHandles cannot be supported then the factory
    77  * methods must consistently throw {@link java.lang.UnsupportedOperationException}.
    77  * methods must consistently throw {@link java.lang.UnsupportedOperationException}.
    78  * The methods of this class throw {@link java.lang.UnsupportedOperationException}
    78  * The methods of this class throw {@link java.lang.UnsupportedOperationException}
    79  * if the operating system does not allow access to query or kill a process.
    79  * if the operating system does not allow access to query or kill a process.
    80  *
    80  *
       
    81  * <p>
       
    82  * The {@code ProcessHandle} static factory methods return instances that are
       
    83  * <a href="{@docRoot}/java/lang/doc-files/ValueBased.html">value-based</a>,
       
    84  * immutable and thread-safe.
       
    85  * Use of identity-sensitive operations (including reference equality
       
    86  * ({@code ==}), identity hash code, or synchronization) on these instances of
       
    87  * {@code ProcessHandle} may have unpredictable results and should be avoided.
       
    88  * Use {@link #equals(Object) equals} or
       
    89  * {@link #compareTo(ProcessHandle) compareTo} methods to compare ProcessHandles.
       
    90  *
    81  * @see Process
    91  * @see Process
    82  * @since 1.9
    92  * @since 1.9
    83  */
    93  */
    84 public interface ProcessHandle extends Comparable<ProcessHandle> {
    94 public interface ProcessHandle extends Comparable<ProcessHandle> {
    85 
    95 
    86     /**
    96     /**
    87      * Returns the native process ID of the process. The native process ID is an
    97      * Returns the native process ID of the process. The native process ID is an
    88      * identification number that the operating system assigns to the process.
    98      * identification number that the operating system assigns to the process.
       
    99      * The operating system may reuse the process ID after a process terminates.
       
   100      * Use {@link #equals(Object) equals} or
       
   101      * {@link #compareTo(ProcessHandle) compareTo} to compare ProcessHandles.
    89      *
   102      *
    90      * @return the native process ID of the process
   103      * @return the native process ID of the process
    91      * @throws UnsupportedOperationException if the implementation
   104      * @throws UnsupportedOperationException if the implementation
    92      *         does not support this operation
   105      *         does not support this operation
    93      */
   106      */
   335      * The process is considered alive as long as the PID is valid.
   348      * The process is considered alive as long as the PID is valid.
   336      *
   349      *
   337      * @return {@code true} if the process represented by this
   350      * @return {@code true} if the process represented by this
   338      *         {@code ProcessHandle} object has not yet terminated
   351      *         {@code ProcessHandle} object has not yet terminated
   339      */
   352      */
   340    boolean isAlive();
   353     boolean isAlive();
       
   354 
       
   355     /**
       
   356      * Returns a hash code value for this ProcessHandle.
       
   357      * The hashcode value follows the general contract for {@link Object#hashCode()}.
       
   358      * The value is a function of the {@link #getPid getPid()} value and
       
   359      * may be a function of additional information to uniquely identify the process.
       
   360      * If two ProcessHandles are equal according to the {@link #equals(Object) equals}
       
   361      * method, then calling the hashCode method on each of the two objects
       
   362      * must produce the same integer result.
       
   363      *
       
   364      * @return a hash code value for this object
       
   365      */
       
   366     @Override
       
   367     int hashCode();
       
   368 
       
   369     /**
       
   370      * Returns {@code true} if {@code other} object is non-null, is of the
       
   371      * same implementation, and represents the same system process;
       
   372      * otherwise it returns {@code false}.
       
   373      * @implNote
       
   374      * It is implementation specific whether ProcessHandles with the same PID
       
   375      * represent the same system process. ProcessHandle implementations
       
   376      * should contain additional information to uniquely identify the process.
       
   377      * For example, the start time of the process could be used
       
   378      * to determine if the PID has been re-used.
       
   379      * The implementation of {@code equals} should return {@code true} for two
       
   380      * ProcessHandles with the same PID unless there is information to
       
   381      * distinguish them.
       
   382      *
       
   383      * @param other another object
       
   384      * @return {@code true} if the {@code other} object is non-null,
       
   385      *         is of the same implementation class and represents
       
   386      *         the same system process; otherwise returns {@code false}
       
   387      */
       
   388     @Override
       
   389     boolean equals(Object other);
   341 
   390 
   342     /**
   391     /**
   343      * Compares this ProcessHandle with the specified ProcessHandle for order.
   392      * Compares this ProcessHandle with the specified ProcessHandle for order.
   344      * The order is not specified, but is consistent with {@link Object#equals},
   393      * The order is not specified, but is consistent with {@link Object#equals},
   345      * which returns {@code true} if and only if two instances of ProcessHandle
   394      * which returns {@code true} if and only if two instances of ProcessHandle