1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| public class TaskExtractorService {
private static final Logger LOGGER = LoggerFactory.getLogger(TaskExtractorService.class);
public TaskExtractorService() {
super();
}
private Boolean avancementThreads;
public Boolean etatThreads(){
return avancementThreads;
}
public String executeJob(final EntrepriseRequestData requetePoste, Client esClient, EntrepriseRequestProperties mRequestProperties, String path) throws InterruptedException {
String data ="{}";
EntrepriseRejectedExecutionHandler rejectionHandler = new EntrepriseRejectedExecutionHandler();
//Get the ThreadFactory implementation to use
ThreadFactory threadFactory = Executors.defaultThreadFactory();
//creating the ThreadPoolExecutor
ThreadPoolExecutor executorPool = new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors(), 10, 100, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(1024), threadFactory, rejectionHandler);
//start the monitoring thread
Map<String, Object> dataPostMap = requetePoste.getRequetesPoster();
int nbreTotalPage = Integer.valueOf(String.valueOf(dataPostMap.get(RequestHelper.NBRE_PAGE))) ;
int pageSize = Integer.valueOf(String.valueOf(dataPostMap.get(RequestHelper.PAGE_SIZE))) ;
//submit work to the thread pool
List<String> lstItem = new ArrayList<String>(nbreTotalPage);
for(int i=1; i<nbreTotalPage+1; i++){
EntrepriseWorkerTask uneTask = new EntrepriseWorkerTask("iteration " +i ,esClient,requetePoste, mRequestProperties, i, pageSize,path,lstItem);
executorPool.submit(uneTask);
}
try{
ObjectMapper mapper = new ObjectMapper();
executorPool.shutdown();
data = mapper.writeValueAsString(lstItem);
if(LOGGER.isDebugEnabled()){
}
} catch (JsonGenerationException e) {
if(LOGGER.isErrorEnabled()){
LOGGER.error("Erreur de serialisation ", e );
}
} catch (JsonMappingException e) {
if(LOGGER.isErrorEnabled()){
LOGGER.error("Erreur de serialisation ", e );
}
} catch (IOException e) {
if(LOGGER.isErrorEnabled()){
LOGGER.error("Erreur de serialisation ", e );
}
}
return data;
}
} |
Partager