Reputation: 41
I'm running a service of generating a big file (It is a report in BIRT) in Java back code and it takes a lot of time my question is what is the best way to manage it with
daemon = true or daemon = false
and the priority
new Thread(new Runnable() {
public void run(){
try {
task.run();
engine.destroy( );
}
catch ( EngineException e1 ) {
System.err.println( "Report " + reportFilepath + " run failed.\n" );
System.err.println( e1.toString( ) );
}
}
}).start();
Upvotes: 2
Views: 437
Reputation: 42966
Creating new Thread()
s in Java EE is considered bad practice. Instead, you should use a service such as ManagedExecutorService
(MES) and submit runnables to it.
The benefit of using a MES over running your own threads is that the resources used by a MES can be controlled by the Java EE app server.
Now to answer your question about daemon threads and priorities.
daemons: Submitting tasks to an MES is always non-blocking, and the result of a task can optionally be checked, so this essentially makes these tasks daemon threads.
priority: there isn't a Java EE standard way that I know of to control thread priority. You will have to check with your application server implementation to see if there are properties you can pass in during task submit to indicate a thread priority.
Upvotes: 2
Reputation: 3654
There is only one difference between a daemon thread and a normal thread: The existence of a normal, running thread will prevent the JVM from shutting itself down, but the existence of a running daemon thread will not. There is no impact on performance
Upvotes: 0