Multiple threads accessing the database: one with a long transaction, one with short transactions

Let's say I have a desktop application that acts like a garage for a bunch of cars:

@Entity
public class Garage {
    private List<Car> cars = new ArrayList<Car>();
    ...
}

In the desktop application there is a button “Simulation”, which starts a new thread and starts calling methods on the garage, car, wheel, etc. This simulation can take up to 10 minutes. At the moment, I have a class that looks like this:

beginTransaction();
Garage garage = garageDao.findGarage(1);
List<Car> cars = garage.getCars();
for (Car car : cars) {
    // call methods on the car to lazily fetch other things like wheels...
}
commitTransaction();

This code only reads and never writes.

Thus, the above can take a lot of time depending on how badly the cars need the service. Although this happens, the user can continue using the desktop application. They can change the color of the car that is used in the above transaction.

, ? , , ?

+5
3

? , ( JPA2). ( ​​) .

+4

, , .

: (, , ).

0

:

. .

, , , , .

0

All Articles