Reputation: 9103
I have a simple application that fetches some data from ONE table on db (MySQL 5.1) via Hibernate and display the content. The main framework used is Spring 3.0. The query runs correctly in @Transactional(read-only) (+second cache level). The problems come out running some concurrent tests with 20/30 requests against the same page. Some page-requests return 500 instead of 200. I suppose that is due to @Transactional doesn't manage multi-thread access (pls correct me if I am wrong).
In the controller I have something like this:
List<String> names = usersService.getUserNames(); // this executes query in @Transactional env
doSomething(names);
the logs say that "doSomething" threws some NullPointerException as there are not data in the list passed.
Is there a way to implement a multi-thread access manager with Spring+Hibernate that manages concurrent requests to db?
Upvotes: 0
Views: 1575
Reputation: 597016
@Transactional is working perfectly fine in multithreaded applications. In fact, all web applications are multithreaded, and each spring bean singleton instance handles all requests. So the issue is not there.
When you get error 500, you should check the logs files. If nothing's there, make sure you haven't swallowed some exception.
Upvotes: 1
Reputation: 6289
You need to make sure that a separate database connection is allocated to every incoming request. Connections should be managed in a pool. The size of the database connection pool would determine (indirectly) how many requests your application can server simultaneously.
Upvotes: 1