Java Reference
In-Depth Information
/**
* Prints a list of jobs to the system log.
*/
public void runJobReport() {
List<Jobs> jobs = jobsFacade.getJobList();
System.out.println("Job Listing Report");
System.out.println("=====================");
for (Jobs job : jobs) {
System.out.println(job.getTitle() + " " + job.getDivision());
}
}
/**
* Prints a list of products
*/
void runProductReport() {
System.out.println("Querying the database");
Path reportFile = Paths.get("ProductReport.txt");
try (BufferedWriter writer = Files.newBufferedWriter(
reportFile, Charset.defaultCharset())) {
Files.deleteIfExists(reportFile);
reportFile = Files.createFile(reportFile);
writer.append("Product Listing Report");
writer.newLine();
writer.append("===================");
writer.newLine();
List<Product> products = productFacade.obtainProduct();
for (Product product : products) {
writer.append(product.getName());
writer.newLine();
}
writer.flush();
} catch (IOException exception) {
System.out.println("Error writing to file");
}
}
}
Lastly, the report needs to be invoked by the ManagedExecutorService that was configured within the web.xml .
In this example, the ManagedExecutorService is injected into a Servlet, which is then used to invoke the report, as
seen in the following code:
import java.io.IOException;
import java.io.PrintWriter;
import java.util.concurrent.Future;
import javax.annotation.Resource;
import javax.enterprise.concurrent.ManagedExecutorService;
 
Search WWH ::




Custom Search