0

in a webapp i want to run an async thread for a long process and let the client knows the progress status. For this i thought to use this abstract class:

public abstract class ThreadProvider implements Runnable{

    protected Thread thread;

    public boolean create() throws SystemException{
        if(thread!=null && thread.isAlive()) throw new SystemException("Il processo è già in esecuzione");
        thread = new Thread(this);
        thread.start();
        return true;
    }
}

And this is my impl:

@Service @Transactional
public class ChiusuraProvider extends ThreadProvider {

    private static Logger gdf = Logger.getLogger("gdf");
    private static Logger log = Logger.getLogger(ChiusuraProvider.class);

    protected Dao dao;
    protected CinetelProvider cinetelProvider;

    @Override
    public void run() {...}
}

Everything works: the thread starts and seems that the autowire works... however Hibernat did not find any session (maybe because i change thread)... how to solve this?

Thanks

4

1 回答 1

1

@Transactional在这种情况下不起作用,请参阅10.5.1 了解 Spring 框架的声明式事务实现

您可以在方法中使用程序化事务管理 ( TransactionTemplate) run,或者将事务逻辑提取到单独的 bean 中并制作@Transactional

于 2012-07-05T09:14:42.530 回答