SystemUtils xref
1 /**
2 * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3 */
4 package net.sourceforge.pmd.util;
5
6 import java.util.concurrent.ExecutorService;
7 import java.util.concurrent.Executors;
8
9 public final class SystemUtils {
10
11 private SystemUtils() {
12 // this is a utility class and cannot be instantiated
13 }
14
15 /**
16 * Do we have proper permissions to use multithreading?
17 */
18 public static final boolean MT_SUPPORTED;
19 static {
20 boolean error = false;
21 try {
22 /*
23 * ant task ran from Eclipse with jdk 1.5.0 raises an AccessControlException
24 * when shutdown is called. Standalone pmd or ant from command line are fine.
25 *
26 * With jdk 1.6.0, ant task from Eclipse also works.
27 *
28 * Bugs related to this hack:
29 * http://sourceforge.net/p/pmd/bugs/1025/
30 * http://sourceforge.net/p/pmd/bugs/670/
31 */
32 ExecutorService executor = Executors.newFixedThreadPool(1);
33 executor.shutdown();
34 } catch (RuntimeException e) {
35 error = true;
36 System.err.println("Disabling multithreading - consider to upgrade to java 1.6");
37 System.err.println("See also: http://sourceforge.net/p/pmd/bugs/670/");
38 }
39 MT_SUPPORTED = !error;
40 }
41 }