Nifi: Threads in nifi

自作多情 提交于 2019-12-11 06:46:48

问题


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. how can i prevent getting file data by several processor at a time except using keep file =false action?
  2. Is it possible to use Thread.sleep inside Execute script processor code?
  3. Is it possible to make same logic by groovy?

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);

回答1:


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

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.

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

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.

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

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

Is it possible to make same logic by groovy?

you can do everything in groovy :)



来源:https://stackoverflow.com/questions/46843397/nifi-threads-in-nifi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!