I am building a billing system. The system needs to generate monthly invoices to Clients.
What I am doing now is using a For loop to check all the clients their previous invoices and decide if it is the time to generate a invoice for the client.
If there are huge number of clients in the database, I think it could be very heavy to do so.
What is the standard way of generating invoices? Is it possible to make cron jobs that records a client’s next invoice date and only check a particular client when it is the time to generate an invoice.
Thanks a million
There is no standard way. But this task is indeed a typical candidate for a batch job. Either run it at the end of the month if you bill all clients at the same time or daily and select only the clients that are billable based on some date criteria. For each client, do what you have to. Depending on the size of your data, JPA might not be appropriate (or maybe consider Hibernate’s
StatelessSessionor even forget it).For the scheduler part, I’ve seen most often enterprise scheduler like Quartz or even bigger dedicated solutions like Control-M, Dollar-U, TNG Workload, etc.
I strongly advice to NOT create one job per client. This is really not a good solution (hell to administrate, won’t scale, etc).