Currently I am working on an Report generator based application as part of which when ever a user logs in and tries to download a report he will end up in calling below method as part of flow
which executes list of queries to fetch required data and return result.
Note : some queries can take 40-60 mins to execute.
Nowadays I did come up across a strange issue where I could see some times the report never resumes after triggering post below code [ Observation was found via logs].
So I suspect does Thread.yield() can result into such scenario's. Since all reports invoking this code flow having same thread priority.
I am not sure the use of Thread.yield in this flow as this is an legacy app, So can anyone guide me if such code can result in infinite waiting state for an thread?
Below is the basic Pseudo code representation of flow, Kindly let me know if any additional information is required. Thanks in advance
Class A {
void m1(reportName) {
try {
// an unique request id gets created for each report generation request
Callable<ReportDownload> = new Download(request, requestid);
FutureTask<ReportDownload> futureTask = new FutureTask<>(download);
ExecutorService executorService = Executors.newFixedThreadPool(1);
executorService.execute(futureTask);
downloadResponse = futureTask.get();
executorService.shutdown();download
} catch (Throwable drt) {
// logs
} finally {
// does terminal operations
}
}
Class Download {
genrate(reortName) {
List sqllist = // fecth all 3 queries related to connector and store in lis
runQueries(sqllist)
}
// the list sqllist will always have 3 queries and these 3 queries will differ for each and every report
List runQueries(sqllist) {
List list = new ArrayList() // used to store result of each query
for (int i = 0; i != sqllist.size(); ++i) {
Thread.yield();
DBConnection dbconnection = null;
try {
dbconnection = // creates db connection
String query = sqllist.get(i);
/* uses DB connection pool and exectes query and store result
* someting like as shown below
*/ And there is no issue with query or dbconnection
DBResult DBResult= dbconnection.retrieve(sql);
// proces returnes result and store in list.
list.add(DBResult);
}
catch (SQLException e) {
// log sql exception
}
}
return list;
}
```