0

I am trying to create a task inside my webapp, which runs in a thread of it's own. It is a monitoring task that should run for the entire duration of the application. For this purpose, I have created a class that looks like:

public class MonitoringTask implements Runnable {
    @Override
    public void run() {
       // perform monitoring task action
    }
}

However, I get the "PMD.DoNotUseThreads" error mentioned here. If creating threads by implementing Runnable is not the recommended way in a J2EE webapp, what is?

witchking
  • 173
  • 2
  • 8
  • 1
    Which version of the J2EE/JEE spec are you using? Latest versions support container managed `Executor`s (read thread pools). In older versions, you have to live with the warning. – Nikos Paraskevopoulos Jan 20 '15 at 08:18
  • further reading as this has been asked many times before: http://stackoverflow.com/questions/3212255/java-ee-specification-and-multi-threading – Gimby Jan 20 '15 at 09:35
  • @NikosParaskevopoulos - I am not really sure about the version of the spec. I think the PMD ruleset is common across the company. Thanks for the pointer to the ManagedExecutorService though, did not know about the new Concurrent Utils. – witchking Jan 20 '15 at 16:37

1 Answers1

1

A java job (e.g. quartz) can be used to monitor after specified interval. This will ensure that the thread is not running forever. Can be used in J2EE environment.

sashwat
  • 597
  • 3
  • 8