zjffdu commented on issue #10408: [FLINK-14992][client] Add job listener to 
execution environments
URL: https://github.com/apache/flink/pull/10408#issuecomment-561677677
 
 
   I don't think we should enforce user to write code like this, this is not a 
user-friendly api. 
   Personally, I don't think we should care whether user accidentally close 
JobClient in JobListener, if they do that, then it is their mistake. The good 
practise is who create resource, then who clean the resource. Here it is flink 
create JobClient, then it should be flink to clean it instead of asking user to 
clean this resource.  Take the following method as one example
   ```
   private void method_1(InputStream in) {
   ...
   }
   ```
   
   Should `method_1` close InputStream ? I don't think so. 
   
   Another solution I can think of is that we can pass `JobContext` instead of 
`JobClient`. And user can create `JobClient` via `JobContext`. e.g.
   
   ```
   @Override
   public void onJobSubmitted(JobContext jobContext, Throwable throwable) {
     try (JobClient jobClient = jobContext.createJobClient()) {
       ...
     }
   }
   ```
   Because in this approach, user have to create JobClient explicitly, then it 
is their responsibility to clean this resource.
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to