English 中文(简体)
Spring Batch resourceless JobRepository
原标题:

I m using Spring Batch for a system that does a lot of batch operations.
I m using SimpleJobRepository with in memory DAOs.
I would like to know if there is a way to avoid using a JobRepository? something similar to the resourceless transaction manager?
The reason i m asking is that the system should run constantly without restarting and i have some concerns about the memory it will be consuming.
I know i can use a database based JobRepositry, but frankly, I really don t need one at all.

If there is no way to do so i will appreciate it if someone can reassure me about the memory consumption problem.

Thanks.

最佳回答

You must use job repository as it holds info about the job context. the solution for your case is - make your job repository with scope="prototype" this will cerate a new in-memory dao (map implementation) for each job, and thus no memory problem. the overhead of creating new instance each time is meaningless in terms of batch jobs.

问题回答

In-Memory implementation has a major drawback : you can t use multithreading in your batchs.

So you must use a database repository. I suggest you use H2 SQL : it s an embedded database very light. We use it for our unit tests.

It works very well with Hibernate.

The advantage of this method over Ben s one is you can connect to you memory database to check the jobs statuses (and date of launches, etc ...).

I think as long as my batch processing code is thread safe , it should not matter whether the Repository is in Memory or Database. Yes you might loose some of the clustering benefits which you can get if you are using DB but if I have only one Batch Job running on my server and its using Multiple threading to do its work, that should be fine.





相关问题
Recommended way to develop using Jetty and Eclipse

I am currently developing a J2EE application and I would like to use Jetty. I would like to have iot integrated with Eclipse, so I could debug the appliaction. I ve tried out couple of plugins (...

Call function periodically in Java

we need run one function periodically in Java web application . How to call function of some class periodically ? Is there any way that call function when some event occured like high load in server ...

Why make an EJB rather than a Web Service?

I would have thought that there is a lot of information out there on this, but I haven t found anything that really answers my question. What are the advantages of making an EJB rather than a web ...

Where should I put this configuration setting?

I m designing a fairly small web application which will run on a Sun application server (v9.1). It only has a few pages, no database of its own, and will retrieve/update data via web services. There s ...

JNDI Names -- Is Prefix "jdbc/" needed?

What s up with JNDI names? I m trying to get a javax.sql.DataSource using the new annotations feature of Java 5. It s not working for me, so I want to ask... I have a in my web.xml, inside of it is ...

hibernate interceptors : afterTransactionCompletion

I wrote a Hibernate interceptor : public class MyInterceptor extends EmptyInterceptor { private boolean isCanal=false; public boolean onSave(Object entity, Serializable arg1, Object[] arg2, String[]...

热门标签