Results 1 to 4 of 4

Thread: taskexecutor and transactions

  1. #1

    Arrow 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. #2
    Join Date
    Nov 2004
    Location
    Hilversum - The Netherlands
    Posts
    1,054

    Default

    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);
        }
    }

  3. #3
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    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

  4. #4

    Default

    Quote 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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •