JEP 102 Process Updates revised API draft

Paul Sandoz paul.sandoz at oracle.com
Tue Mar 10 09:50:41 UTC 2015


On Mar 6, 2015, at 7:58 PM, Roger Riggs <Roger.Riggs at Oracle.com> wrote:
>> 2) I know there has been a lot of discussion about the use of CF,
>>     but I have a few more comments:
>>          a) Both onExit and onProcessExit are implemented to unconditionally
>>         throw UOE. Is the intention to make the implementation of these
>>         methods optional? If so, then UOE should be documented, If not,
>>         then I think they can be abstract, right?
> There are existing non-jdk implementations of Process and it would be source
> incompatible if default implementations were not supplied.  So, not abstract.
> 
> Since the behavior applies to Process, the note in the class documentation
> defines the behavior.
> "Methods of {@code Process} that are not otherwise specified or overridden throw
> {@link java.lang.UnsupportedOperationException}."
> 
> More direct documentation could be provided in the override of onExit
> but that would raise the visibility to ordinary developers who should use
> onProcessExit that returns the correctly typed CF and not onExit.
> The note should be sufficient for implementers without distracting the ordinary developer.
> 
> Perhaps, a description similar to that used in destroy(), the behavior of Processes
> returned from ProcessBuilder can be more tightly specified. Alternatively,
> ProcessBuilder could specify the behavior of Process instances it returns, at present,
> the behavior of the Process instances is split between the two classes.
> 

Throwing USO for default implementations is a warning sign to me that something does not fit quite right. It feels like we are giving up :-)  

I now see Process.getPid was previously added and it throws USO by default. So we might be stuck due to the tricky nature of this area. 

Any sub-type of Process that does not override getPid will essentially result in that USO being propagated to many ProcessHandle methods that depend on the PID (parent, children, allChildren, info, compareTo). That effectively renders ProcessHandle almost useless for sub-types outside of our control that that not been updated.

Is it common to sub-type Process? If so then perhaps Process should not extend ProcessHandle and instead there should be a way to view a Process as a ProcessHandle, whose default implementation is:

  return ProcessHandle.of(getPid()); // throws USO if getPid does 

(java.lang.ProcessImpl could implement Processhandle thereby the implementation is "return this".)

Thus once you have a ProcessHandle instance (from whatever source) it's possible to operate on it without fear of a USO.


A possible default implementation for Process.onProcessExit could be:

  return CF.supplyAsync(() -> { this.waitFor(); return p}, cachedThreadPool);

Paul.



More information about the core-libs-dev mailing list