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