[ 
https://issues.apache.org/jira/browse/FLINK-9730?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16533904#comment-16533904
 ] 

ASF GitHub Bot commented on FLINK-9730:
---------------------------------------

Github user nekrassov commented on a diff in the pull request:

    https://github.com/apache/flink/pull/6247#discussion_r200423552
  
    --- Diff: 
flink-examples/flink-examples-streaming/src/main/java/org/apache/flink/streaming/examples/async/AsyncIOExample.java
 ---
    @@ -116,8 +116,8 @@ public void cancel() {
        private static class SampleAsyncFunction extends 
RichAsyncFunction<Integer, String> {
                private static final long serialVersionUID = 
2098635244857937717L;
     
    -           private static ExecutorService executorService;
    -           private static Random random;
    --- End diff --
    
    No, my point is: if we are making executorService and random 
instance-specific - then we don't need to synchronize on class (lines 148 and 
163).
    If we want to keep executorService and random as static, then we need to 
make counter static too (line 122). 
    I think having all three (executorService, random, counter) as static is 
best.
    
    Having executorService and random as static, but counter as 
instance-specific will not work when someone creates a second instance of 
SampleAsyncFunction. In second SampleAsyncFunction the counter will be 0 and we 
will re-intialize static executorService and random, thus interfering with the 
first SampleAsyncFunction object.


> avoid access static via class reference
> ---------------------------------------
>
>                 Key: FLINK-9730
>                 URL: https://issues.apache.org/jira/browse/FLINK-9730
>             Project: Flink
>          Issue Type: Improvement
>    Affects Versions: 1.5.0
>            Reporter: lamber-ken
>            Assignee: lamber-ken
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 1.6.0
>
>
> [code refactor] access static via class reference



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to