Announcement Announcement Module
Collapse
No announcement yet.
taskexecutor and transactions Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • taskexecutor and transactions

    Hi! I'm trying to build a task for taskexecutor that would use hibernate to insert data into db.

    Now, as I'm using lobhandler, this task needs to be run in transaction. Any pointers how to do that properly?

    here is the idea;

    Code:
    public HibernateTask implements runnable {
    ..
    ..
    public void run() {
          //do hibernate stuff
    }
    }
    
    and new you would do
    taskexecutor.execute(new HibernateTask());

  • #2
    One way of doing it, is to think in a different way about the threads. Threads are a way of executing methods. So why no execute a method on some applicationservice, just like your controllers do.

    Code:
    class FireServiceImpl implements FireService{
       void fire(long id){
          Employee e = employeeRepository.load(id);
          e.fire();
      }
    }
    You can wrap a transaction around this service.

    And you can call this service from a runnable:


    Code:
    class FireRunnable implements Runnable{
        FireService service;
        long id;
    
        public void run(){
             service.fire(id);
        }
    }

    Comment


    • #3
      I'd prefer to do it that way, but as an alternative what about programmatic declaration maybe via the TransactionTemplate.
      http://www.springframework.org/docs/...n-programmatic

      Comment


      • #4
        Originally posted by Alarmnummer View Post
        One way of doing it, is to think in a different way about the threads. Threads are a way of executing methods. So why no execute a method on some applicationservice, just like your controllers do.
        Why of course. Why didn't I think of that in the first place.. Could be that this -30 celcius weather has somehow freezing my brain activity

        Thanks,
        Karri

        Comment

        Working...
        X