为啥我的自定义函数调用方法中的 println 语句没有出现在日志中?

Posted

技术标签:

【中文标题】为啥我的自定义函数调用方法中的 println 语句没有出现在日志中?【英文标题】:Why do println statements in my custom Function's call method not appear in the logs?为什么我的自定义函数调用方法中的 println 语句没有出现在日志中? 【发布时间】:2017-05-26 13:05:32 【问题描述】:

我的方法:-

private static Function<ConsumerRecord<String, String>, StreamDataWrapper> createFunction()
    System.out.println("***** inside create function ******");
    ObjectMapper mapper = new ObjectMapper();
    Function<ConsumerRecord<String, String>, StreamDataWrapper> function = new Function<ConsumerRecord<String, String>, StreamDataWrapper>()

        public StreamDataWrapper call(ConsumerRecord<String, String> c) throws JsonParseException, JsonMappingException, IOException
            System.out.println("**** inside call of Function *******");
            System.out.println("**** Consumer record "+c);
            StreamData sd = mapper.readValue(c.value(), StreamData.class);
            System.out.println("**** StreamData "+sd);
            StreamDataWrapper sw = new StreamDataWrapper(sd);
            System.out.println("**** StreamDataWrapper "+sw);
            return sw;
        

    ;
    System.out.println("***** End of create function ******");
    return function;

我从另一种方法调用此createFunction(),但问题是它执行所有语句而不是statements inside call()。这是我的方法的output。 操作:-

***** inside create function ******
***** End of create function ******

它不打印其他输出语句。 以下是我正在使用的依赖项

<dependency>
        <groupId>org.apache.spark</groupId>
        <artifactId>spark-core_2.11</artifactId>
        <version>2.0.1</version>
        <exclusions>
            <exclusion>
                <groupId>com.google.guava</groupId>
                <artifactId>guava</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

【问题讨论】:

您如何以及在何处使用来自createFunction()function JavaRDD&lt;StreamDataWrapper&gt; streamDataRdd = rdd.map(createFunction()); 然后呢?什么动作会触发你的函数调用? 实际过程是在那之后使用CassadnraUtil 我正在向数据库中插入数据,但它没有向数据库中插入任何数据,我已经检查了一切以确定问题,最初我以为是cassandra问题但不是那个,后来在RDD上工作,最后我发现问题出在call方法 请给我看代码你能用show操作符显示行,然后把写信给Cassandra放在一边,以确保它不会导致问题吗?跨度> 【参考方案1】:

这里可能有两个问题:

    call 不打印消息 call 确实被调用了,但您没有查看正确的日志。

您确实会看到一些消息,因为具有该功能的管道已实例化(准备执行),但由于您没有触发任何操作,因此您看不到内部消息。就是这样 1。

至于另一个可能的问题,我会说您查看了错误的日志。您应该查看函数运行所在的执行程序日志。 2.

【讨论】:

我的兴趣不是看日志,它不执行call方法中的语句,那些是应该执行的语句。为了测试这些语句是否被执行,我只放了一些System.out.println() 语句。我观察到这些语句没有被执行,你知道如何让这些语句(在call内)被执行吗?

以上是关于为啥我的自定义函数调用方法中的 println 语句没有出现在日志中?的主要内容,如果未能解决你的问题,请参考以下文章

C语言编程:请问为啥我的自定义函数全部无法执行,急急

为啥在我的自定义 UIView 类中没有调用 init(frame: CGRect)?

为啥不调用基于 nib 的自定义表格单元格的 init 方法

java中System.out.println()方法为啥只能放在方法体内(原理)

为啥 autorest 用 Swagger 中的对象替换我的自定义结构?

将自定义活动添加到 UIActivityController 的问题