NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

//global variable.
Optional executionStatus = Optional.empty();

/********** STAGE 1: PRODUCER ***********************/
Map<String, Integer> columnName= new HashMap<String, Integer>();
Set<String> journeyID = new LinkedHashSet<String>();

FileInputStream readExcel = new FileInputStream(pathOfExcel);
XSSFWorkbook readBook= new XSSFWorkbook(readExcel);
XSSFSheet readSheet = readBook.getSheet("New_Device_Management"); //Input sheet name to be referred.


//Traversing through rows
Row firstRow = readSheet.getRow(0); //First row is header

int minValueForIteration = firstRow.getFirstCellNum(); //getFirst column index
int maxValueForIteration = firstRow.getLastCellNum(); //getLast column index
for(int i=minValueForIteration; i<maxValueForIteration; i++)
{
Cell valueOfCell = firstRow.getCell(i);
//Mapping column name to index since position of column may not be same
columnName.put(valueOfCell.getStringCellValue(), valueOfCell.getColumnIndex());
}


columnName.forEach((k,v)->
System.out.println("Key " + k + " | value" + v)
);


Iterator<Row> rowIterator = readSheet.rowIterator();//Iterate through rows

//Execution Status column Iteration starts here
//Journey of respective row with execution status as "Yes" is stored.
//Set initiated stores the value avoiding duplicate element.
//Size of set determines the number of thread to be initiated and Name of thread
rowIterator.forEachRemaining(x-> {
//ExecutionStatus must be a global variable.
executionStatus = Optional.ofNullable(x.getCell(columnName.get("ExecutionStatus")).toString());
if("yes".equalsIgnoreCase((String) executionStatus.get()))
{
journeyID.add(x.getCell(columnName.get("Journey")).toString());

}

});

System.out.println("Number of Thread to be initiated - " + journeyID.size());


/************STAGE 2: Thread Pool Executor ********/

//Intial core pool size - 2. Assuming min two thread always run. If it is lesser, a new thread shall get created to handle it.
//Max Pool size- decided based on size of set.
//Max duration for a thread to stay idle - 30 minutes.
// Thread that can be queued - 2
//if CorepoolSize and MaxpoolSize are same-> it is fixed thread count concept.
ThreadFactory threadFactory = Executors.defaultThreadFactory();//Created to alter threadname, priority etc.
ThreadPoolExecutor executorPool = new ThreadPoolExecutor(2, journeyID.size(), 30, TimeUnit.MINUTES, new ArrayBlockingQueue<Runnable>(3), threadFactory);

//Print all this Logs in debug mode.
System.out.println("Pool Size - " + executorPool.getCorePoolSize());
System.out.println("Core Pool Size - " + executorPool.getPoolSize());
System.out.println("Max allocated size - " + executorPool.getMaximumPoolSize());
System.out.println("is thread idle?" + executorPool.prestartCoreThread()); //Returns true or false based on thread idle state. Thread starts based on task submitted to executor.

Iterator<String> threadName = journeyID.iterator();
while(threadName.hasNext())
{
//At a time only 3 threads can run considering memory management.,
Runnable executeThread = new ThreadConcept(threadName.next());
executorPool.execute(executeThread);
}

/***********Stage 3: Operation **********/

//With thread name as primary key one has to iterate through the cells.

/*********** STage 4 : Reporting ***********/

//Flush and close method of reporting to be invoked here

/***********Stage 5: Termination ************/
//Terminator to be called after reporting is completed.
try{
executorPool.shutdown();
while (!executorPool.isTerminated()) {
System.out.println("Finished All Threads");
}
}catch(RejectedExecutionException E){
System.out.println("Task cannot be accepted due to shut down");
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.