【发布时间】:2023-03-19 14:25:02
【问题描述】:
@Autowired
ThreadPoolTaskScheduler taskScheduler;
@Autowired
SendUpdatesRunnable sendUpdatesRunnable;
private void createJob(String timezone) {
ZonedDateTime zoned = LocalDate.now().atTime(10, 11).atZone(ZoneId.of(timezone));
sendUpdatesRunnable.timezone = timezone;
taskScheduler.schedule(
sendUpdatesRunnable,
Date.from(zoned.toInstant())
);
}
和
@Component
public class SendUpdatesRunnable implements Runnable{
@Autowired
ProductRepository productRepository;
String timezone;
@Override
@Transactional
public void run() {
List<Product> newProds = productRepository.findProductByCreateDateTimeIsAfter(LocalDateTime.now().minusHours(24));
List<Product> updatedProds = productRepository.findProductByUpdateDateTimeIsAfter(LocalDateTime.now().minusHours(24));
//System print out timezone variable = null
}
}
【问题讨论】:
-
你能解释一下你在问什么吗?你能指望什么?会发生什么,何时以及如何发生?
标签: spring spring-boot threadpool runnable threadpoolexecutor