You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Looking for suggestions on how to update the database in a separate thread pool using ScheduledExecutorService
The below is a simplified approach which I used to perform a DB update in a separate thread. Within the run method, the record.name is being updated, however outside the context of the below function, the database changes are not being reflected.
Can anyone share what are the best practices to perform a DB update using separate threads?
val runnable = threadContext.contextualRunnable(CustomRunnable(customRepository))
scheduledExecutorService.schedule(runnable, 2, TimeUnit.SECONDS)
class CustomRunnable(private val customRepository: CustomRepository) : Runnable { @transactional
override fun run() {
val record = customRepository.findByName("randomName")
record.name = "newName"
customRepository.persist(record)
}
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Looking for suggestions on how to update the database in a separate thread pool using ScheduledExecutorService
The below is a simplified approach which I used to perform a DB update in a separate thread. Within the run method, the record.name is being updated, however outside the context of the below function, the database changes are not being reflected.
Can anyone share what are the best practices to perform a DB update using separate threads?
@Inject
val threadContext: ThreadContext
val runnable = threadContext.contextualRunnable(CustomRunnable(customRepository))
scheduledExecutorService.schedule(runnable, 2, TimeUnit.SECONDS)
class CustomRunnable(private val customRepository: CustomRepository) : Runnable {
@transactional
override fun run() {
val record = customRepository.findByName("randomName")
record.name = "newName"
customRepository.persist(record)
}
}
Beta Was this translation helpful? Give feedback.
All reactions