2015-04-27 49 views
0

上週五我實現了這個功能,但它不工作,但我不能再工作了,而且我瘋了!!春季異步組件不能正常工作

這是我當前的應用程序上下文配置。

<?xml version="1.0" encoding="UTF-8" standalone="no"?> 
    <beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:task="http://www.springframework.org/schema/task" 
    xmlns:util="http://www.springframework.org/schema/util" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd 
    http://www.springframework.org/schema/task 
    http://www.springframework.org/schema/task/spring-task-3.0.xsd 
    http://www.springframework.org/schema/util 
    http://www.springframework.org/schema/util/spring-util-3.1.xsd"> 

     <context:component-scan base-package="com.greenvalley.etendering"> 
     <context:exclude-filter type="annotation" expression="com.greenvalley.etendering.annotation.NoAutoScan" /> 
    </context:component-scan> 

    <task:annotation-driven/> 

然後我有我的組件。

 @Component 
     @Transactional 
     @Configuration 
     @EnableAsync 
     public class AsyncDocumentGenerationImpl implements   AsyncDocumentGeneration { 

private static final Logger LOGGER = LoggerFactory.getLogger(AsyncDocumentGenerationImpl.class); 


private static final SimpleDateFormat timestampFormat = new SimpleDateFormat("yyyyMMddHHmmssSSS"); 

private final String mimeType = "application/pdf"; 
private final FileType fileType = FileType.PDF; 

@Inject 
private DocumentGenerationService documentGenerationService; 

@Inject 
private DocumentService documentService; 


@Async 
public Future<Integer> generateDocumentPerCandidate(final PublicProcurement publicProcurement, final DocumentType documentType, final Candidacy candidacy, final Assessment assessment) 
     throws FileFormatException, DocumentServiceException, IOException, JAXBException, CmisDocumentException { 

    return new AsyncResult<>(FeedbackActions.SUCCESS.getCode()); 
} 

}

和成分從其它服務調用。

 private DeferredResult<Integer> generateDocumentsPerCandidates(DocumentGroup documentGroup, DocumentType documentType, PublicProcurement publicProcurement) 
     throws FileFormatException, DocumentServiceException, IOException, JAXBException, CmisDocumentException { 
    List<Future<Integer>> candidaciesResults = new ArrayList<>(); 
    for (Candidacy candidacy : publicProcurement.getCandidacies()) { 
      Future<Integer> candidacyResult = asyncDocumentGeneration.generateDocumentPerCandidate(publicProcurement, 
        documentType, candidacy, documentGroup.getAssessment()); 
      candidaciesResults.add(candidacyResult); 

    } 
    DeferredResult<Integer> future = new DeferredResult<>(); 
    asyncDocumentGeneration.manageResults(candidaciesResults, future); 
    return future; 
} 

我認爲必須是與applicationContext配置或異步組件的註釋相關的東西。但事情並非在調用異步方法時,不由其他線程執行。

請有人看到這裏的奇怪嗎?

問候。

回答

1

嘗試設置池的大小explicite:

<task:annotation-driven executor="myExecutor" scheduler="myScheduler"/> 
<task:executor id="myExecutor" pool-size="5"/> 
<task:scheduler id="myScheduler" pool-size="10"/> 
+0

it's看來,現在工作爲一個異步方法。但現在奇怪的是,上週五我可以在日誌文件中清理異步線程事務「SimpleAsyncTaskExecutor-1」,但現在我不能! – paul