Announcement Announcement Module
Collapse
No announcement yet.
Parallelize Hibernate Queries Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Parallelize Hibernate Queries

    Hi,

    I have 3 queries that I would like to execute in parallel.

    My service layer is intercepted by a HibernateInterceptor.

    By seeing my logs, the 3 threads come at the same time into my DAO methods, but the HibernateTemplate.execute() gets synchronized by the TransactionSynchronizationManager (I think).

    I tryed to mark my methods with "PROPAGATION_REQUIRES_NEW, ISOLATION_DEFAULT, readOnly", thinking that because a new transaction was required, a new Session would be created and the job could be done in parallel.

    But it results in my methods being synchronized :-(

    here is my config :

    Code:
    	<bean id="myDao" 
    	  class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    	  <property name="transactionManager">
    	    <ref bean="transactionManager"/>
    	  </property>
    	  <property name="target">
    	    <ref bean="myDaoTarget"/>
    	  </property>
    	  <property name="transactionAttributes">
    	    <props>
    	      <prop key="get*">PROPAGATION_REQUIRES_NEW, ISOLATION_DEFAULT, readOnly</prop>	      
    	    </props>
    	  </property>
    	</bean>
    
    	<bean id="hibernateInterceptorBeanNameProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
    	  <property name="beanNames"><value>*Service</value></property>
    	  <property name="interceptorNames">
    	    <list>
    	      <value>hibernateInterceptor</value>
    	    </list>
    	  </property>
    	</bean>
    
    	<bean id="hibernateInterceptor" class="org.springframework.orm.hibernate.HibernateInterceptor">
    	  <property name="sessionFactory">
    	    <ref bean="sessionFactory"/>
    	  </property>
    	</bean>
    do I have any chance doing this stuff in parallel ?

    thanks,

    Fred

  • #2
    Why would you want to run them in parallel? At application and db core things will run sequentelly - you'll just have the illusion of things running at the same time.
    Moreover, when transactions are involved, things will run one after another (that's the whole point of transactions after all).

    Comment


    • #3
      Why would you want to run them in parallel?
      My question is How to run them in paralell?
      and not Is it a good choice to run them in paralell?
      If I wanted to validate my design, I would have posted on the 'Architecture Discussion' topic

      Anyway, the answer to you question is : the problem is the network delay and not the processing time.

      At application and db core things will run sequentelly - you'll just have the illusion of things running at the same time.
      Servers sometimes have more than one CPU :-)
      Also, it's not because a webserver runs on a single CPU machine that all requests must be served by a single thread, even if at CPU level thing's do get run sequentially...

      Moreover, when transactions are involved, things will run one after another (that's the whole point of transactions after all).
      Well, because those data's are read only, I had no problem running them without transaction, but that's not how the HibernateTemplate behaves.
      All I want is a trick so my queries get sent and my results get fetched in parallel

      thanks anyway,

      Fred

      Comment


      • #4
        My question is How to run them in paralell?
        and not Is it a good choice to run them in paralell?
        If I wanted to validate my design, I would have posted on the 'Architecture Discussion' topic
        fverbist, ppl think of a solution that doesn't address their problem.
        Anyways, I think you should try with your queries outside a transaction and see how things work. I you still see synchronization start start looking at the source code - you might see synchronization at jdbc driver level

        Comment

        Working...
        X