Nifi:nifi 中的线程 [英] Nifi: Threads in nifi

查看:62
本文介绍了Nifi:nifi 中的线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道线程在 nifi 中是如何工作的,我的意思是一个处理器有一个线程,或者它们在一个主线程中? 也许我想从处理器获取一个文件,然后我想更新它

I want to know how threads work in nifi i mean one processor has one thread or they are in one main thread? perhaps i want to get one file from processor and then i want to update it

  1. 如何防止多个处理器同时获取文件数据除了使用 keep file =false 操作?
  2. 是否可以在执行脚本处理器代码中使用 Thread.sleep?
  3. 是否可以通过 groovy 实现相同的逻辑?

我尝试使用 java 文件锁,但这里是我的代码,它似乎不太好用,

I tried to use java File locks but it doesn't seem to work good here is my code,

     File file = new File("C://Users//user//Desktop//try2//nifi-
      1.3.0//4//conf2.xml");
        String content = "";
        String material = "";
        BufferedReader s;
        BufferedWriter w;
        int m;
        RandomAccessFile ini = new RandomAccessFile(file, "rwd");
        FileLock lock = ini.getChannel().lock();
        DocumentBuilder dBuilder;
        Document document, doc;
        String date="";
        String data="";
        boolean make = false;
        try {

            String sCurrentLine;
            s = new BufferedReader(Channels.newReader(ini.getChannel(), "UTF-8"));
            while ((sCurrentLine = s.readLine()) != null) {
                content += sCurrentLine;
            }
            ini.seek(0);

推荐答案

我想知道线程在 nifi 中是如何工作的我的意思是一个处理器有一个线程还是它们在一个主线程中?

I want to know how threads work in nifi i mean one processor has one thread or they are in one main thread?

Nifi 有一个可配置的线程池 (三明治菜单 -> 控制器设置 -> 一般) 并且当任何处理器计划执行时,系统从池中取出空闲线程,在此执行处理器线程,并将线程返回到线程池.因此,每个处理器都在一个单独的随机线程中执行.

Nifi has a configurable pool of threads ( sandwich menu -> controller settings -> general ) and when any processor planned for execution, system takes free thread from the pool, executes processor in this thread, and returns thread to thread pool. So, each processor executes in a separate random thread.

如何防止多个处理器同时获取文件数据除了使用 keep file =false 操作?

how can i prevent getting file data by several processor at a time except using keep file =false action?

您需要存储一个标志已处理的文件XXX.您将如何存储它 - 这是您的选择.例如,您可以创建一个同名但添加扩展名的空文件:conf.xml ->conf.xml.done.并在代码中检查文件 conf.xml.done 是否存在,然后跳过 conf.xml 文件处理.

you need to store a flag file XXX processed. how you going to store it - it's your choice. for example you can create an empty file with the same name but with added extension: conf.xml -> conf.xml.done. and in code just check if file conf.xml.done exists then skip conf.xml file processing.

您可以将标志存储在数据库、缓存系统等中

you can store the flag in the database, caching system, etc.

是否可以在执行脚本处理器代码中使用 Thread.sleep?

Is it possible to use Thread.sleep inside Execute script processor code?

可能,但我认为这没有任何意义.

possible, but I don't see any sense for this.

是否可以通过 groovy 实现相同的逻辑?

Is it possible to make same logic by groovy?

你可以在 groovy 中做任何事情 :)

you can do everything in groovy :)

这篇关于Nifi:nifi 中的线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆