2

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();
chuyleonel
  • 41
  • 5

2 Answers2

2

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.

Andy Guibert
  • 41,446
  • 8
  • 38
  • 61
0

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

Reinard
  • 3,624
  • 10
  • 43
  • 61
  • and what priority of use will you recommend me in a java ee app? – chuyleonel Nov 04 '16 at 18:39
  • By default I would leave it as normal. Unless there is an actual reason to change it. The following article does a decent job at explaining the impact of changing priority on Windows or Linux without going to in depth. http://www.javamex.com/tutorials/threads/priority_what.shtml – Reinard Nov 04 '16 at 18:47