View | Details | Raw Unified | Return to bug 53492
Collapse All | Expand All

(-)java/org/apache/jasper/JspC.java (-18 / +89 lines)
Lines 43-48 Link Here
43
import java.util.Stack;
43
import java.util.Stack;
44
import java.util.StringTokenizer;
44
import java.util.StringTokenizer;
45
import java.util.Vector;
45
import java.util.Vector;
46
import java.util.concurrent.Callable;
47
import java.util.concurrent.ExecutionException;
48
import java.util.concurrent.ExecutorCompletionService;
49
import java.util.concurrent.ExecutorService;
50
import java.util.concurrent.Executors;
46
51
47
import javax.servlet.jsp.tagext.TagLibraryInfo;
52
import javax.servlet.jsp.tagext.TagLibraryInfo;
48
53
Lines 126-131 Link Here
126
    protected static final String SWITCH_ENCODING = "-javaEncoding";
131
    protected static final String SWITCH_ENCODING = "-javaEncoding";
127
    protected static final String SWITCH_SMAP = "-smap";
132
    protected static final String SWITCH_SMAP = "-smap";
128
    protected static final String SWITCH_DUMP_SMAP = "-dumpsmap";
133
    protected static final String SWITCH_DUMP_SMAP = "-dumpsmap";
134
    protected static final String SWITCH_THREAD_COUNT = "-threadCount";
129
    protected static final String SHOW_SUCCESS ="-s";
135
    protected static final String SHOW_SUCCESS ="-s";
130
    protected static final String LIST_ERRORS = "-l";
136
    protected static final String LIST_ERRORS = "-l";
131
    protected static final int INC_WEBXML = 10;
137
    protected static final int INC_WEBXML = 10;
Lines 209-214 Link Here
209
     * is UTF-8.  Added per bugzilla 19622.
215
     * is UTF-8.  Added per bugzilla 19622.
210
     */
216
     */
211
    protected String javaEncoding = "UTF-8";
217
    protected String javaEncoding = "UTF-8";
218
    
219
    /** The number of threads to use; default is two per core */
220
    protected int threadCount = 0;
212
221
213
    // Generation of web.xml fragments
222
    // Generation of web.xml fragments
214
    protected String webxmlFile;
223
    protected String webxmlFile;
Lines 363-368 Link Here
363
                smapSuppressed = false;
372
                smapSuppressed = false;
364
            } else if (tok.equals(SWITCH_DUMP_SMAP)) {
373
            } else if (tok.equals(SWITCH_DUMP_SMAP)) {
365
                smapDumped = true;
374
                smapDumped = true;
375
            } else if (tok.equals(SWITCH_THREAD_COUNT)) {
376
                setThreadCount(nextArg());
366
            } else {
377
            } else {
367
                if (tok.startsWith("-")) {
378
                if (tok.startsWith("-")) {
368
                    throw new JasperException("Unrecognized option: " + tok +
379
                    throw new JasperException("Unrecognized option: " + tok +
Lines 720-725 Link Here
720
        return javaEncoding;
731
        return javaEncoding;
721
    }
732
    }
722
733
734
    public int getThreadCount() {
735
        return threadCount;
736
    }
737
    
738
    public void setThreadCount(String threadCount) {
739
        if (threadCount == null) return;
740
        int newThreadCount;
741
        if (threadCount.endsWith("C")) {
742
            try {
743
                double factor = Double.parseDouble(threadCount.substring(0, threadCount.length() - 1));
744
                newThreadCount = (int) (factor * (double) Runtime.getRuntime().availableProcessors());
745
            } catch (NumberFormatException e) {
746
                throw new BuildException("Couldn't parse thread count: " + threadCount);
747
            }
748
        } else {
749
            try {
750
                newThreadCount = Integer.parseInt(threadCount);
751
            } catch (NumberFormatException e) {
752
                throw new BuildException("Couldn't parse thread count: " + threadCount);
753
            }
754
        }
755
        if (newThreadCount < 1) throw new BuildException("There must be at least one thread: " + newThreadCount);
756
        this.threadCount = newThreadCount;
757
    }
758
    
723
    /**
759
    /**
724
     * Sets the encoding to use for
760
     * Sets the encoding to use for
725
     * java files.
761
     * java files.
Lines 1305-1332 Link Here
1305
            initWebXml();
1341
            initWebXml();
1306
1342
1307
            Iterator<String> iter = pages.iterator();
1343
            Iterator<String> iter = pages.iterator();
1308
            while (iter.hasNext()) {
1344
            if (threadCount == 0) {
1309
                String nextjsp = iter.next().toString();
1345
                threadCount = 2 * Runtime.getRuntime().availableProcessors();
1310
                File fjsp = new File(nextjsp);
1346
            }
1311
                if (!fjsp.isAbsolute()) {
1347
            ExecutorService threadPool = null;
1312
                    fjsp = new File(uriRootF, nextjsp);
1348
            try {
1313
                }
1349
                threadPool = Executors.newFixedThreadPool(threadCount);
1314
                if (!fjsp.exists()) {
1350
                ExecutorCompletionService<Void> service = new ExecutorCompletionService<Void>(threadPool);
1315
                    if (log.isWarnEnabled()) {
1351
                int fileCount = 0;
1316
                        log.warn
1352
                while (iter.hasNext()) {
1317
                            (Localizer.getMessage
1353
                    String nextjsp = iter.next().toString();
1318
                             ("jspc.error.fileDoesNotExist", fjsp.toString()));
1354
                    File fjsp = new File(nextjsp);
1355
                    if (!fjsp.isAbsolute()) {
1356
                        fjsp = new File(uriRootF, nextjsp);
1319
                    }
1357
                    }
1320
                    continue;
1358
                    if (!fjsp.exists()) {
1359
                        if (log.isWarnEnabled()) {
1360
                            log.warn
1361
                                (Localizer.getMessage
1362
                                 ("jspc.error.fileDoesNotExist", fjsp.toString()));
1363
                        }
1364
                        continue;
1365
                    }
1366
                    String s = fjsp.getAbsolutePath();
1367
                    if (s.startsWith(uriRoot)) {
1368
                        nextjsp = s.substring(uriRoot.length());
1369
                    }
1370
                    if (nextjsp.startsWith("." + File.separatorChar)) {
1371
                        nextjsp = nextjsp.substring(2);
1372
                    }
1373
                    service.submit(new ProcessFile(nextjsp));
1374
                    fileCount++;
1321
                }
1375
                }
1322
                String s = fjsp.getAbsolutePath();
1376
                for (int i = 0; i < fileCount; i++) {
1323
                if (s.startsWith(uriRoot)) {
1377
                    service.take().get();
1324
                    nextjsp = s.substring(uriRoot.length());
1325
                }
1378
                }
1326
                if (nextjsp.startsWith("." + File.separatorChar)) {
1379
            } catch (InterruptedException e) {
1327
                    nextjsp = nextjsp.substring(2);
1380
                throw new JasperException(e);
1381
            } catch (ExecutionException e) {
1382
                if (e.getCause() instanceof JasperException) {
1383
                    throw (JasperException) e.getCause();
1384
                } else {
1385
                    throw new JasperException(e.getCause());
1328
                }
1386
                }
1329
                processFile(nextjsp);
1387
            } finally {
1388
                if (threadPool != null) threadPool.shutdownNow();
1330
            }
1389
            }
1331
1390
1332
            completeWebXml();
1391
            completeWebXml();
Lines 1354-1359 Link Here
1354
            }
1413
            }
1355
        }
1414
        }
1356
    }
1415
    }
1416
    
1417
    private class ProcessFile implements Callable<Void> {
1418
        private final String file;
1419
        private ProcessFile(String file) { this.file = file; }
1420
        
1421
        @Override
1422
        public Void call() throws Exception {
1423
            processFile(file);
1424
            return null;
1425
        }
1426
        
1427
    }
1357
1428
1358
    // ==================== protected utility methods ====================
1429
    // ==================== protected utility methods ====================
1359
1430
(-)java/org/apache/jasper/resources/LocalStrings.properties (+1 lines)
Lines 184-189 Link Here
184
\    -javaEncoding <enc> Set the encoding charset for Java classes (default UTF-8)\n\
184
\    -javaEncoding <enc> Set the encoding charset for Java classes (default UTF-8)\n\
185
\    -source <version>   Set the -source argument to the compiler (default 1.6)\n\
185
\    -source <version>   Set the -source argument to the compiler (default 1.6)\n\
186
\    -target <version>   Set the -target argument to the compiler (default 1.6)\n\
186
\    -target <version>   Set the -target argument to the compiler (default 1.6)\n\
187
\    -threadCount <count>   Number of threads. \"2.0C\" means two threads per core\n\
187
188
188
jspc.webxml.header=<?xml version="1.0" encoding="ISO-8859-1"?>\n\
189
jspc.webxml.header=<?xml version="1.0" encoding="ISO-8859-1"?>\n\
189
\n\
190
\n\

Return to bug 53492