Details
-
Type:
Bug
-
Status: Closed
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: 1.10.5 (Hopper SR5)
-
Fix Version/s: 1.11 RC1 (Ingalls), 2.0 M2 (Kay)
-
Component/s: None
-
Labels:
-
Environment:Mac OS X Sierra 10.12.1
Description
I'm using Stream's to loop through each element in a Repository in an @Scheduled method. After running 200 times I get the following error:
2016-12-13 09:40:39.159 WARN 51004 --- [pool-2-thread-1] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 0, SQLState: null
2016-12-13 09:40:39.159 ERROR 51004 --- [pool-2-thread-1] o.h.engine.jdbc.spi.SqlExceptionHelper : [pool-2-thread-1] Timeout: Pool empty. Unable to fetch a connection in 2 seconds, none available[size:200; busy:200; idle:0; lastwait:2000].
The Repository is defined as such:
public interface PushNotificationRepository extends JpaRepository<PushNotification, Long> { @Query(value = "select p from PushNotification p") Stream<PushNotification> findAllAndStream(); }
The Service is defined like this:
@Service @Transactional() public class PushNotificationFlusherService { private static final Logger LOGGER = LoggerFactory.getLogger(PushNotificationFlusherService.class); private final PushNotificationRepository pushNotificationRepository; @Autowired public PushNotificationFlusherService(PushNotificationRepository pushNotificationRepository) { this.pushNotificationRepository = pushNotificationRepository; } @Scheduled(fixedDelay = 5000) protected void flushPushNotificationQueue() { LOGGER.info("Flushing push notifications"); try (Stream<PushNotification> pushNotifications = pushNotificationRepository.findAllAndStream()) { pushNotifications.forEach((PushNotification pushNotification) -> { // Send notification }); } LOGGER.info("Flushed push notifications"); }
I've tried using @Transactional( readOnly=true) but it does not make a difference.
Attachments
Issue Links
- depends on
-
DATACMNS-959 Register repository interceptor to allow detecting a surrounding transaction
-
- Closed
-
- is duplicated by
-
DATAJPA-989 CrudRepository; return Stream<T>; The object is already closed [90007-192]; could not advance using next()
-
- Resolved
-