I have a class that implements Runnable interface. When I start the the thread I give it a name so I could find the thread later on
LoadRawDataThread loadRawDataThread = new LoadRawDataThread(filePath + fileName, delimiter, noOfColumn, sqlDBname,
FileUtil.getParameter("transactionType_" + hiddenFieldNo, parameterMap),
tableName, seqNo, requestBulkSize, encoding);
Thread thread = new Thread(loadRawDataThread);
thread.setName(fileName);
thread.start();
Now, in other method I would like to get this loadRawDataThread object because I have volatile there that I would like to grab. I did something like this but this will return Thread object hence I cant see my volatile there.
private Thread getThreadByName(String threadName) {
for (Thread t : Thread.getAllStackTraces().keySet()) {
logger.info("The name of the thread is :------->>>>>>> " + t.getName());
if (t.getName().equalsIgnoreCase(threadName.trim())) {
return t;
}
}
return null;
}
Any ideas how could it be done?