@@ -553,7 +553,6 @@ protected void restoreAptProblems() {
553
553
554
554
protected void processCompiledUnits (int startingIndex , boolean lastRound ) throws java .lang .Error {
555
555
CompilationUnitDeclaration unit = null ;
556
- ProcessTaskManager processingTask = null ;
557
556
try {
558
557
if (this .useSingleThread ) {
559
558
// process all units (some more could be injected in the loop by the lookup environment)
@@ -596,30 +595,37 @@ protected void processCompiledUnits(int startingIndex, boolean lastRound) throws
596
595
}));
597
596
}
598
597
} else {
599
- processingTask = new ProcessTaskManager (this , startingIndex );
600
- int acceptedCount = 0 ;
601
- // process all units (some more could be injected in the loop by the lookup environment)
602
- // the processTask can continue to process units until its fixed sized cache is full then it must wait
603
- // for this this thread to accept the units as they appear (it only waits if no units are available)
604
- while ( true ) {
598
+ try ( ProcessTaskManager processingTask = new ProcessTaskManager (this , startingIndex )){
599
+ int acceptedCount = 0 ;
600
+ // process all units (some more could be injected in the loop by the lookup environment)
601
+ // the processTask can continue to process units until its fixed sized cache is full then it must wait
602
+ // for this this thread to accept the units as they appear (it only waits if no units are available)
603
+ this . requestor . startBatch ();
605
604
try {
606
- unit = processingTask .removeNextUnit (); // waits if no units are in the processed queue
607
- } catch (Error | RuntimeException e ) {
608
- unit = processingTask .unitToProcess ;
609
- throw e ;
605
+ Collection <CompilationUnitDeclaration > units ;
606
+ do {
607
+ try {
608
+ units = processingTask .removeNextUnits ();
609
+ } catch (Error | RuntimeException e ) {
610
+ unit = processingTask .getUnitWithError ();
611
+ throw e ;
612
+ }
613
+ for (CompilationUnitDeclaration u : units ) {
614
+ unit = u ;
615
+ reportWorked (1 , acceptedCount ++);
616
+ this .stats .lineCount += unit .compilationResult .lineSeparatorPositions .length ;
617
+ this .requestor .acceptResult (unit .compilationResult .tagAsAccepted ());
618
+ if (this .options .verbose )
619
+ this .out .println (Messages .bind (Messages .compilation_done ,
620
+ new String [] { String .valueOf (acceptedCount ),
621
+ String .valueOf (this .totalUnits ), new String (unit .getFileName ()) }));
622
+ }
623
+ // processingTask had no more units available => use the time to flush:
624
+ this .requestor .flushBatch ();
625
+ } while (!units .isEmpty ());
626
+ } finally {
627
+ this .requestor .endBatch ();
610
628
}
611
- if (unit == null ) break ;
612
- reportWorked (1 , acceptedCount ++);
613
- this .stats .lineCount += unit .compilationResult .lineSeparatorPositions .length ;
614
- this .requestor .acceptResult (unit .compilationResult .tagAsAccepted ());
615
- if (this .options .verbose )
616
- this .out .println (
617
- Messages .bind (Messages .compilation_done ,
618
- new String [] {
619
- String .valueOf (acceptedCount ),
620
- String .valueOf (this .totalUnits ),
621
- new String (unit .getFileName ())
622
- }));
623
629
}
624
630
}
625
631
if (!lastRound ) {
@@ -640,10 +646,6 @@ protected void processCompiledUnits(int startingIndex, boolean lastRound) throws
640
646
this .handleInternalException (e , unit , null );
641
647
throw e ; // rethrow
642
648
} finally {
643
- if (processingTask != null ) {
644
- processingTask .shutdown ();
645
- processingTask = null ;
646
- }
647
649
reset ();
648
650
this .annotationProcessorStartIndex = 0 ;
649
651
this .stats .endTime = System .currentTimeMillis ();
0 commit comments