package com.rest.service;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import lombok.extern.log4j.Log4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.rest.dto.AllotmentRequestDto;
import com.rest.model.FPSStore;
import com.rest.repository.FPSStoreRepository;
@Service
@Log4j
public class UnitWiseEntitlementCalculationSchedulerService {
@Autowired
ApplicationContext applicationContext;
@Autowired
FPSStoreRepository fpsStoreRepository;
@Transactional(propagation = Propagation.REQUIRES_NEW)
@Scheduled(cron = "30 01 12 ? * *")
public void unitCardWiseEntitlementCalculation() {
log.info("<--Starts UnitWiseEntitlementCalculationSchedulerService .unitCardWiseEntitlementCalculation-->");
try {
List<Future<AllotmentRequestDto>> list = new ArrayList<Future<AllotmentRequestDto>>();
List<FPSStore> fpsStoreList = new ArrayList<FPSStore>();
fpsStoreList.add(fpsStoreRepository.getOne(1l));
/** to create one executerService for each of the FpsStore */
ExecutorService executerService = Executors.newFixedThreadPool(25);
for (FPSStore fpsStore : fpsStoreList) {
UnitWiseEntitlementCalculationSchedulerCallableService unitWiseECSCService = (UnitWiseEntitlementCalculationSchedulerCallableService) applicationContext
.getBean("StockAllotmentScheduler1");
unitWiseECSCService.setFpsStore(fpsStore);
Future<AllotmentRequestDto> f = executerService
.submit(unitWiseECSCService);
list.add(f);
}
for (Future<AllotmentRequestDto> ref : list) {
ref.get();
}
executerService.shutdown();
} catch (Exception exception) {
log.error("Exception -:", exception);
exception.printStackTrace();
}
log.info("<--Ends UnitWiseEntitlementCalculationSchedulerService .unitCardWiseEntitlementCalculation-->");
}
}
package com.omneagate.rest.service;
import java.util.concurrent.Callable;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.log4j.Log4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.rest.dto.AllotmentRequestDto;
import com.rest.model.FPSStore;
@Log4j
@Service("StockAllotmentScheduler1")
@Scope("prototype")
public class UnitWiseEntitlementCalculationSchedulerCallableService implements
Callable<AllotmentRequestDto> {
@Setter
@Getter
FPSStore fpsStore;
@Autowired
UnitWiseEntitlementCalculationSchedulerWrapper unitWiseEntitlementCalculationSchedulerWrapper;
@Transactional
@Override
public AllotmentRequestDto call()
throws Exception {
log.info("");
unitWiseEntitlementCalculationSchedulerWrapper
.calculateCardUnitWiseCalculation(fpsStore);
return null;
}
}
在第
行UnitWiseEntitlementCalculationSchedulerCallableService unitWiseECSCService = (UnitWiseEntitlementCalculationSchedulerCallableService) applicationContext
.getBean("StockAllotmentScheduler1");
我正在获得类强制转换异常..
但在打印对象时,它正在打印com.rest.service.UnitWiseEntitlementCalculationSchedulerCallableService@fee68cd
并打印该类,即
unitWiseECSCService.getClass()
正在打印 - :类com.sun.proxy.$Proxy349
并在打印班级名称,unitWiseECSCService.getClass().getName()
时打印为
com.sun.proxy.$Proxy349
非常感谢帮助。