multithreading - Task's threads lunched by Spring Scheduler -


We are building a system that has data layers, business layers, service levels ... also a scheduler If the job is to execute every 5 seconds and look for work in a database table, if the job is to be executed, then this task is used to execute this task. The problem is that within the execution, the work needs to be read and updated from the data layer to the institutions, some of which are being lazy loading and when it crashes with some lazy loading exception, prematurely session Stops.

  Error: org.springframework.scheduling.support.TaskUtils $ LoggingErrorHandler - failed to start a collection of unexpected error occurred org.hibernate.LazyInitializationException: lazily role in Scheduled Tasks: - org.hibernate .collection.internal.AbstractPersistentCollection.throwLazyInitializationAccession session (AbstractPersistentCollection com.soft1.pack1.data.entity.InitialAlignment.initialAlignment, could not activate the proxy .java: 566) at org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded ( AbstractPersistentCollection.java:186) at org.hibernate.collection.internal.AbstractPersistentCollectionInitialize (AbstractPersistentCollection.java) 454 org.hibernate.collection. internal.AbstractPersistentCollection.read (AbstractPersistentCollection.java:124) org.hibernate.collection.internal.PersistentBag.iterator (PersistentBag.java:266) on com.soft1.pack1.data.entity.InitialAlignment.getDefenses (on InitialAlignment.java: 80) tor.TaskTaskExecutorMethod sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43) on com.soft1.pack1.data.entity.TaskMatch.run (TaskMatch.java:74) com.soft1.pack1.negocio.TaskTaskExecu on sun.reflect.GeneratedMethodAccessor40.invoke (unknown source) at java.lang.reflect.Method.invoke (TaskTaskExecutor.java:61) (method. org.springframework.scheduling.support.ScheduledMethodRunnable on Java.util.concurrent.executors .run (on org.springframework.scheduling.support.DellegatingErrorHandlingRunnable.run) Java org.springframework.scheduling.support on (DelegatingErrorHandlingRunnable.java:54): 606). java.util.concurrent.ScheduledThreadPoolExecutor at $ ScheduledFutureTask.access at $ RunnableAdapter.call (Executors.java:471) java.util.concurrent.FutureTask.runAndReset (FutureTask.java:304) $ 301 (ScheduledThreadPoolExecutor.java:178) Java In .util.concurrent.ScheduledThreadPoolExecutor $ ScheduledFutureTask.run java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java1145) at (ScheduledThreadPoolExecutor.javahew93) java.util.co at ncurrent.ThreadPoolExecutor $ Worker.run (ThreadPoolExecutor .java: 615) at java.lang.Thread.run (Thread.java:745)  

We feel that our problem is more architecture than the technology.

Any help will be helpful.

Thank you.

EDIT1: (from @radai comments)

  1. In the initial alignment there is a property called security, which is defined as lazy A list is repeated on the property (such as @OneToMany (fetch = FetchType.LAZY))
  2. Database Access Layer uses Hibernation This layer opens a hibernate session, becomes a unit, And closes the hibernate session
"post-text" itemprop = "text">

I'm not sure about this But that is what I think is that happened to you:

  1. You have some kind of database access layer that uses hibernate The layer opens a hibernate session, becomes a unit, and closes the hibernate session
  2. Initial algorithm
  3. initial alignment < / Code> has a property called security , which defines some list as idle on the asset (as in That is the @OneToMany (Fetch = FetchType.LAZY) ), which means that it is not obtained from the database until it is used.
  4. Your task ( TaskMatch ), which runs in, but lazy properties can only be obtained, while the hibernate session which is initial alignment example They are still alive. A different thread and this unit is given, trying to use the lazy area, but the hibernate session that has been creating the object has already stopped, so hibernate can not be returned to the database and get your list. , And can achieve the exception that you are receiving


Comments